Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Calling IVPRK of IMSL FNL 7.0.1 from C++ Code crashes after first iteration

Haroon_B_
Beginner
845 Views

Dear Sir/Madam,

We are developing a program in which the initial value problem solver IVPRK is used. The program is developed in multilanguage C++ and FORTRAN. We have a valid license of IMSL FNL 7.0.1, purchased with Intel XE Studio.

During the solution the C++ code calls the IVPRK solver through a wraper in Fortran. The IVPRK then directs the solution towards an external function, which further directs another function, written in C++, which actually calculates the vectors Y and YPrime.

The first iteration at T=0.00 goes very fine and completes a full cycle of calling intermediate functions from C++ (Step 1) => Fortran Wraper (Step 2) => IVPRK (Step 3) => External Fn in Fortran Step (4) => External Function in C++ that calculates  Y and YPrime (Step 5). In all these steps the programmer has found that all the required vectors like Y and YPrime from start to end go very well and correct without any error.  

Once after Step 5, it comes back to Step 4, Returns the values and when it goes back on top of the subroutine of Step 4, the program crashes and the following messages comes out:

"No Symbol file loaded for imslmkl_dll.dll"

and once after pressing the Continue button on debug mode makes the program crashed. We have tried several initial input options and checked the code vis-a-vis the given examples of IMSL FNL 7.0.1, we think there shall not be anything that is missing. Right now it is a total black out at this stage. Your support will highly be appreciated.

Kind Regards,

Haroon

 


 

0 Kudos
1 Solution
mecej4
Honored Contributor III
845 Views

I am afraid I can only help with some aspects. I do not have MFC installed, nor am I a C++ programmer, and I do not have compatible versions of VS, tools, etc.

On a positive note, I see nothing wrong with your calling IMSL from C through Fortran wrapper routines. In fact, I was able to run a small C program with the same initial values and call your Fortran wrappers and IMSL and obtain a solution to the ODE. The attached Zip file contains the source files. This I did on Windows XP with Parallel Studio 2013SP1, VS2010 and IMSL 7.0, all 32-bit.

Here is how to build and run in a command window:

ifort /LD /Qimsl DFILib.f90 IIVPRK.f90 /link /export:F_IIVPRK
icl /MD drvr.c dfilib.lib
drvr
 0   1.0   7.797e-002   1.465e+000
 1   2.0   8.555e-002   5.785e-001
 2   3.0   2.923e-001   2.497e-001
 3   4.0   1.452e+000   1.879e-001
 4   5.0   4.035e+000   1.451e+000
 5   6.0   1.751e-001   2.251e+000
 6   7.0   6.594e-002   9.061e-001
 7   8.0   1.491e-001   3.660e-001
 8   9.0   6.592e-001   1.879e-001
 9  10.0   3.172e+000   3.560e-001
10  10.0   3.172e+000   3.560e-001

As long as you can make your MFC application call the DLL in the same way that my 25-line C code does, you should be in good shape.

View solution in original post

0 Kudos
8 Replies
mecej4
Honored Contributor III
845 Views

There is a moderate chance of getting the linkage wrong when mixing C and Fortran code. If C++ is used, you will need to add generous helpings of extern "C" {} around the declarations of the Fortran routine prototypes. Furthermore, the data types have to match and multidimensional arrays have to follow Fortran conventions.

With care, you can get this to work, but why not use the IMSL CNL, instead, if your calling routines and the problem functions are coded in C/C++?

The "no symbols loaded" is not a problem, since the IMSL library DLLs are not meant to be debugged, anyway.

0 Kudos
Steve_Lionel
Honored Contributor III
845 Views

He'd need to buy the IMSL CNL separately. The FNL is designed to be called from Fortran and there are lots of ways to get things wrong if you call from other languages.

0 Kudos
Haroon_B_
Beginner
845 Views

Thanks Mecej4 and Steve for the reply. So it means CNL is the only solution! There are a few more functions that we are calling from C++, like curve fitting, and etc., and those are running perfectly fine uptil now.  

I wish MKL had ODE and Optimization routines. I am not sure how stable is the the ODE solver available on Intel website:

https://software.intel.com/en-us/articles/intel-ordinary-differential-equations-solver-library

0 Kudos
mecej4
Honored Contributor III
845 Views

The Intel ODE solver is not supported/maintained, but I have used it in the past and found it to be excellent. It is also designed to match better with how things are done in C. Please take a look at http://www.alglib.net and GNU-GSL. There is also a large and versatile ODE solver written entirely in C: Alan Hindmarsh's Sundials from LLNL, see http://computation.llnl.gov/projects/sundials .

However, switching to CNL is a choice to be made on the basis of convenience versus cost. If you can make up a small example of using FNL with C/C++ that has the same kind of problems as in your big code and post it here, someone may be able to help you find and fix the problem.

0 Kudos
Haroon_B_
Beginner
845 Views

Mecej

Thanks for your help.

Attached is the example with only source code, which has the same setup with same error that we are getting with the bigger code. I hope you will have the FNL license to setup for this example.

Regards and thank you again,

Haroon

 

0 Kudos
mecej4
Honored Contributor III
846 Views

I am afraid I can only help with some aspects. I do not have MFC installed, nor am I a C++ programmer, and I do not have compatible versions of VS, tools, etc.

On a positive note, I see nothing wrong with your calling IMSL from C through Fortran wrapper routines. In fact, I was able to run a small C program with the same initial values and call your Fortran wrappers and IMSL and obtain a solution to the ODE. The attached Zip file contains the source files. This I did on Windows XP with Parallel Studio 2013SP1, VS2010 and IMSL 7.0, all 32-bit.

Here is how to build and run in a command window:

ifort /LD /Qimsl DFILib.f90 IIVPRK.f90 /link /export:F_IIVPRK
icl /MD drvr.c dfilib.lib
drvr
 0   1.0   7.797e-002   1.465e+000
 1   2.0   8.555e-002   5.785e-001
 2   3.0   2.923e-001   2.497e-001
 3   4.0   1.452e+000   1.879e-001
 4   5.0   4.035e+000   1.451e+000
 5   6.0   1.751e-001   2.251e+000
 6   7.0   6.594e-002   9.061e-001
 7   8.0   1.491e-001   3.660e-001
 8   9.0   6.592e-001   1.879e-001
 9  10.0   3.172e+000   3.560e-001
10  10.0   3.172e+000   3.560e-001

As long as you can make your MFC application call the DLL in the same way that my 25-line C code does, you should be in good shape.

0 Kudos
Haroon_B_
Beginner
845 Views

Thanks a lot Mecej.

It is working now. Seems like VS 2015 configuration somehow overrides the original Fortran LIB file during the compilation of C++ code. At first instance we were not successful but later we simple copy and paste the original Fortan DLLs on the debug folder and it is successful now.

Thanks again :). 

0 Kudos
Das__Sanket
Beginner
845 Views

Sir, I am a research scholar at IIT Guwahati and we have purchased imsl. While using IVPRK subroutine once it is working fine unless I make further iteration. Can you please help me in this regards?

0 Kudos
Reply