Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
7015 Discussions

## Using FORTRAN Intel MKL to build CubicSpline() available in scipy.interpolate

Novice
2,372 Views

I would like to implement cubic spline interpolation using Intel MKL in FORTRAN. To make it clear, I coded up an equivalent Python code as follows:

###start of python code for cubic spline interpolation###

from numpy import *
from scipy.interpolate import CubicSpline
from matplotlib.pyplot import *

#Sample data, y_data=sin(x_data)
x_data = [0,1,2,3,4,5,6]
y_data = [ 0,0.84147098,0.90929743,0.14112001,-0.7568025,-0.95892427,-0.2794155]

#Defining interploation points
x = arange(0, 2*pi, 0.2)

#Building the cubic spline using CubicSpline class in scipy.interpolate
cs = CubicSpline(x_data, y_data, axis=0, bc_type='not-a-knot', extrapolate=False)
y_cubicSpline = cs(x)

#Computing the exact values at interpolation points for comparison purposes
y_exact = sin(x)

#Printing the results
print('x y_exact y_cubicSpline')
print('-----------------------------------------')
for i in range(len(x)):
print ("{:.1f} {:.15f} {:.15f}".format(x[i],y_exact[i],y_cubicSpline[i]))

#Plotting the results
plot(x_data, y_data, 'ko', label='Sample Data')
plot(x, y_cubicSpline,'b-', label="Cubic Spline Interpolation")
plot(x, y_exact,'r--', label='Exact Sine Function')
xlabel('x')
ylabel('Sin(x)')
legend(loc='best')
grid()
show()

###end of python code for cubic spline interpolation###

Results are as shown below:

The relevant files are attached as follows:

• cubic_spline_interpolation.txt
• results.txt
• Figure_1.pdf

As I understand, there are some examples regarding the implementation of cubic splines using MKL in FORTRAN in the following directory:

"C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018.5.274\windows\mkl\examples\examples_core_f.zip\datafittingf"

However, I was not able to find the functionality demonstrated above in Python. Could you please help me re-produce the results of the Python code using Intel MKL functionalities in FORTRAN?

Thanks.

1 Solution
Moderator
1,942 Views

Please use the latest version of Intel oneMKL for the best performance so that we could analyze and assist you accordingly. Further performance improvements can be made by using features such as Parallelization, etc.

If you need additional help, please provide more details regarding your use case, system hardware, etc. as performance varies by your usage, configuration, and other factors.

Thanks and Regards,

Praneeth Achanta

9 Replies
Moderator
2,306 Views

Thanks for posting in Intel communities.

A FORTRAN example regarding cubic spline interpolation(dfdcubicspline_interp) is available in oneMKL 2023.1 under the below path.

C:\Program Files (x86)\Intel\oneAPI\mkl\2023.1.0\examples\examples_core_f.zip\f\datafitting\source

Thanks and Regards,

Praneeth Achanta

Novice
2,263 Views

Thank you for your reply. Currently, I do not have MKL 2023. I used the following example (from Version 2018)

"C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018.5.274\windows\mkl\examples\examples_core_f.zip\datafittingf\source\dfdcubicspline_interp.f"

Attached is what I coded up (CubicSplineMKL.f90) using the above example. Since I am not intending to use parallel processing features yet, I removed the blocks from the code (NNBLOCKS). Also, I am only interested in the interpolated points (not the derivative values). The results look good as attached (result.txt).

Could you please let me know if this is implemented correctly? Is there a feature in MKL 2023 that can increase the performance of such computations?

Moderator
2,205 Views

Glad to know the results are satisfactory. For more tips on code optimization and program performance improvement please refer to the below link.

https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2023-0/optimization-and-programming.html

Thanks and Regards,

Praneeth Achanta

Novice
2,097 Views

Hi Praneeth,

Thank you for the follow up. I looked at the link you provided. However, I am not quite sure which part is applicable to my code. Could you please direct me to a particular part that I should look which is related to the cubic spline I implemented?

Best regards,

Moderator
2,113 Views

We have not heard back from you. Could you please provide an update on your issue?

Thanks & Regards,

Praneeth Achanta

Novice
2,042 Views

Hi Praneeth,

Thank you for the follow up. I looked at the link you provided. However, I am not quite sure which part is applicable to my code. Could you please direct me to a particular part that I should look which is related to the cubic spline I implemented?

Best regards,

Moderator
1,943 Views

Please use the latest version of Intel oneMKL for the best performance so that we could analyze and assist you accordingly. Further performance improvements can be made by using features such as Parallelization, etc.

If you need additional help, please provide more details regarding your use case, system hardware, etc. as performance varies by your usage, configuration, and other factors.

Thanks and Regards,

Praneeth Achanta

Novice
1,922 Views

Hi Praneeth,

Best regards,

Moderator
1,873 Views