Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Intel Community
- Software
- Software Development SDKs and Libraries
- Intel® oneAPI Math Kernel Library
- Access violation in spline function

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

netphilou31

New Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-29-2012
01:35 AM

332 Views

Access violation in spline function

In an effort to remove IMSL library from our projects (because of the new licensing policy) I am giving a try to the MKL library. I mainly use cubic spline functions using Intel Visual Fortran Compiler XE on IA-32, version 12.1.1 (Package ID: w_fcompxe_2011.7.258). I have started with from an existing project that compiles and links fine with IMSL (the project exports functions used in Excel through VBA to provide spline features). I have added a new function that uses the spline possibilities of the MKL (10.3 update 10). The call to the function from VBA works fine, but I get an

Best regards.

Link Copied

29 Replies

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-29-2012
02:09 AM

285 Views

There is a Matlab implementation of one-dimensional Akima interpolation which you may find helpful.

netphilou31

New Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-29-2012
02:38 AM

285 Views

Thanks for your reply. Please findattached a ZIP file containingthe IVF project as well as the Excel file that calls the dll with the data used in sheet1 (you will have to change the location of the library in the VBA code). I did not include the module file (MKL_DF) whichis directly accessed from its original location.

Best regards,

netphilou31

New Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-29-2012
06:00 AM

285 Views

Just for giving some additional information. After the access violation message, if I stop into the debugger and loork at the contents of the

Best regards,

Sergey_M_Intel2

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-29-2012
06:18 AM

285 Views

Many thanks for additional detail. Please give us some time to reproduce & root cause the issue.

Sergey

VictoriyaS_F_Intel

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-29-2012
07:27 AM

285 Views

Hi netphilou31,

There're several issues with the subroutine AkimaSpline_MKL that you're using for Akima cubic interpolation.

1. Before calling dfdNewTask1D() function you set ny=nx. This is wrong, because setting ny=nx means that you will construct coefficients for nx Akima cubic splines on the same partition at once. But you only need coefficients for 1 spline. So, to fix the issue please make following change in your code:

! Create Data Fitting task

**ny = 1**

errcode = dfdNewTask1D(task, nx, xx, xhint, ny, yy, yhint)

This was the cause of access violation in you application. There were no enough memory for construction of nx splines.

2. datahint parameter is initialized incorrectly when calling dfdInterpolate1D. You should either skip it, because it's unnecessary in your case, or make following change to the code:

**datahint(1) = 1.d0** ! Dimension of the task

**datahint(2) = dble(DF_NO_APRIORI_INFO)** ! No additional information about breakpoints or sites is provided.

3. Interpolation results are packed into r array - parameter of dfdInterpolate1D function, they aren't returned as the functions' result.

It will be better to use following code sequence to obtain interpolation result:

errcode = dfdInterpolate1D(task, DF_INTERP, DF_METHOD_PP, nsite, site, sitehint, ndorder, dorder, datahint, r, rhint)

call CheckDfError(errcode)

**Y = r(1)**

After applying those three changes described above the code should start working as expected.

Please seefixed file in attachment.

netphilou31

New Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-29-2012
07:59 AM

285 Views

Hi Victoriya,

Thanks a lot ! I did very basic mistakes that I should not have done !

I have changed the code according to your suggestions but unfortunately the * dfdInterpolate1D* function returns always 0 in r(1) whatever the value stored in site(1). If I have correctly understood, the site() array contains the x values for which one wants an interpolation and the r() array contains the results ?

Best regards,

netphilou31

New Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-29-2012
08:21 AM

285 Views

I have found that I have to set the dorder(1) value to 1 to get the interpolated valued in r() instead of 0 as mentionned in the documentation :

dorder: Array of size ndorder that defines the order of the derivatives to be computed at the interpolation sites. If all the elements in dorder are zero, the library computes the spline values only. If you do not need interpolation computations, set ndorder to zero and pass a NULL pointer to dorder.

Moreover, but it is probably not a problem with the example, I get very different results from the DCSAKM function from the IMSL library ! The DCSAKM function gives a very good spline but the one I have used gives a bad one. Probably IMSL is using constraints as first or second derivatives at breakpoints to get better results. Il will check that and try, if possible, to fill the gap between both spline results.

Best regards,

Sergey_M_Intel2

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-29-2012
09:39 PM

285 Views

Please let us know if you still see significant deviation between libraries. If you get stuck then we might have a deeper look at the issue.

Sergey

netphilou31

New Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-29-2012
11:39 PM

285 Views

Please find attached some comparisons I have made between the MKL and IMSL libraries Akima spline functions. As mentioned in my previous message, it is possible that IMSL uses some kind of constrained spline. I have also attached a PDF describing another spline method that you can have a look on. When programmed this method gives very ggod results (even better than the IMSL Akima spline). If you need the Excel workbook and the IVF project I have used please tell me.

Best regards,

Phil.

P.S: For your information, the natural splines give almost the same results in both libraries (and MKL natural spline gives better results than Akima in MKL)

VictoriyaS_F_Intel

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-30-2012
12:47 AM

285 Views

Thank you for your time spent to analyse the issue!

The data you've provided is enough to continue investigation of the differences in Akima splines computations on our side.

Thanks,

Vika

netphilou31

New Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-30-2012
03:11 AM

285 Views

Please find attached another couple of comparisons I have made using the example provided in the IMSL documentation for the CSAKM/DCSAKM function. It seems that the problem lies at the end-points (the Akima spline is similar to the one from IMSL except at the end-points, i.e. in the first two and last two intervals).

Thanks again.

Best regards,

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-30-2012
04:39 AM

285 Views

[bash]cd s:/akima x=0:0.1:1; y=sin(15*x); % 11 data points xi=linspace(0,1,101); yc=sin(15*x); % calculated yi=akima(x,y,xi); % interpolated plot(xi,yi,'-',x,y,'o',xi,yc) xlabel('x'); ylabel('y'); grid legend('Akima','Data','calculated') orient landscape print -dpng 's:/akima/akm.png' [/bash]

Sergey_M_Intel2

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-30-2012
05:10 AM

285 Views

Likewise, if the spline construction and/or evaluation represents performance sensitive part of the application it's certainly make sense touse one fromMKL.

Regards,

Sergey

netphilou31

New Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-30-2012
06:11 AM

285 Views

For my job it is important to avoid overshooting problems so I can use the algorithm proposed by CJC Kruger ; but, because I also want to remove other calls to IMSL functions, I was trying the MKL library. However, I have found that its use was very different from IMSL thus I ran into difficulties for implementing it.

Anyway, are you sure that there is no problems in the MKL for the fitting of the first and last two intervals (as shown on the graphs I have attached previously), because for the internal intervals the results are very close between both libraries. Moreover if the polynomial of the first interval is erroneous, the second is probably also erroneous (because of the continuity of the derivative at the breakpoint).

Best regards,

Phil.

VictoriyaS_F_Intel

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-30-2012
06:31 AM

285 Views

The examples provided by you disclosed the issue in MKL Akima spline construction, which wasn't caught by our internal testing. Thank you very much for your efforts!

Indeed, coeficients of Akima spline are calculated incorrectly for two beginning and two ending intervals. This issue isplanned to be fixed in further MKL releases. Hopefully you will try one ofthem.

Thanks,

Vika

netphilou31

New Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-30-2012
06:48 AM

285 Views

Could it be possible to post a reply on this thread to be informed that the problem is fixed ?

Thanks.

Best regards,

Phil.

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-30-2012
07:57 AM

285 Views

In any case, the Matlab code can be useful in providing test results to validate the results from MKL.

Gennady_F_Intel

Moderator

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-30-2012
09:09 AM

285 Views

regards, Gennady

netphilou31

New Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-30-2012
09:27 AM

285 Views

Hi,

Many thanks to all of you.

I will wait impatiently for the next release.

Best regards,

Many thanks to all of you.

I will wait impatiently for the next release.

Best regards,

netphilou31

New Contributor II

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-30-2012
11:22 PM

147 Views

To complete and to answer to mecej4, the Matlab code is very useful for testing this function because it shows that the routine dfdInterpolate1D returns NaN for a portion of the flat part of the curve when testing the Akima examples (see the attached plot in which I have replaced the NaN values by #VALUE into Excel).

Best regards,

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

For more complete information about compiler optimizations, see our Optimization Notice.