Connect IMSL library to Intel Fortran in Visual Studios - fortran

I try to connect the IMSL library (version 6.0) to Intel Fortran (version 11.1) in Visual Studio (version 2008). The IMSL library is added to the path like this:
$C:\Program Files (x86)\VNI\imsl\fnl600\Intel64\lib
and the "includes" are there as well
$C:\Program Files (x86)\VNI\imsl\fnl600\Intel64\include\dll
$C:\Program Files (x86)\VNI\imsl\fnl600\Intel64\include\static
The program I run to test the installation is:
PROGRAM main
USE RNUN_INT
USE RNSET_INT
IMPLICIT NONE
INTEGER :: ISEED
REAL :: R(5)
ISEED = 123457
CALL RNSET (ISEED)
CALL RNUN (R)
END PROGRAM main
The result I get is Error #7002: Error in opening the compiled module file. Check INCLUDE paths. [RNUN_INT]
What am I missing?

Related

C++-Fortran mixcompile unresolved externals

I am trying to make a fortran-C++ mix compile project. I use the case to test how the visual studio 2017 compiler link the intel fortran .lib file. Here is the example code:
Fortran code here:
!DEC$ IF DEFINED (_DLL)
!DEC$ ATTRIBUTES DLLEXPORT :: ADD
!DEC$ END IF
REAL*8 FUNCTION ADD (A, B, C, D)
REAL*8 B,D
INTEGER*4 A,C
DIMENSION B(4), D(4)
ADD = B(A) + D(C)
RETURN
END
C++ code here:
#include <iostream>
extern "C" {double add_(int *, double[], int *, double[]); }
double ar1[4] = { 1.0, 2.0, 3.0, 4.0 };
double ar2[4] = { 5.0, 6.0, 7.0, 8.0 };
int main()
{
int x, y;
double z;
x = 3;
y = 3;
z = add_(&x, ar1, &y, ar2); /* Call Fortran add routine */
/* Note: Fortran indexes arrays 1..n */
/* C indexes arrays 0..(n-1) */
std::cout << z << std::endl;
return 0;
}
The project setup procedures are:
Open VS studio, create a c++ empty project, add the c++ code in the source file. Solution will be automatically created as well.
Add a new fortran static library project in the solution. Add the fortran code in the source file.
Fortran project-> properties->Libraries->Runtime Libraries-> Debug multithread dll.
Build the fortran project, find the .lib file directory.
C++ project-> linker -> General -> Additional Library Dependencies -> add the .lib file directory here
C++ project-> linker -> Input -> Additional dependencies -> Add .lib file name here end with ";".
Build C++ project.
And the compiler error message is:
1>------ Build started: Project: Cpp_main, Configuration: Debug Win32 ------
1>Source.obj : error LNK2019: unresolved external symbol _add_ referenced in function _main
1>C:\Users\Documents\TEST_Project\MixCompile_Test\Mix_compile\Debug\Cpp_main.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "Cpp_main.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
Why the compiler cannot resolve the external function call even if I assign the .lib directory in C++ project?
Thanks a lot!
Update 22-6-24:
Thank you Steve. I followed your instruction and made configuration in VC++ directories to add the ifortran include and lib directory into it. But new problem happened:
1>------ Build started: Project: Cpp_main, Configuration: Debug Win32 ------
1>LINK : fatal error LNK1104: cannot open file 'msvcprtd.lib'
1>Done building project "Cpp_main.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========
Update 22-06-24
I solved the issue. I will upload the whole solution tomorrow. It's really special problem for VS2017.
Fortran compiler: Inter ifortran19
Cpp compiler: MSVC 2017
Step:
Create your CPP project and solution.
In the solution, add a fortran static library project with name .
Add your fortran headfile and source code in that project.
For every fortran subroutine that will be called in CPP, do like this:
subroutine_name() BIND(C)
USE, INTRINSIC :: ISO_C_BINDING
end subroutine
For CPP headfile, if the fortran compiler is interl fortran, do not add underscore_ after the function name!! Just declare the function name with extern "C" like this:
extern "C"{void <fortran_subroutine>()}
Remember, all the arguments passed from C code should be reference or pointer. Do not pass value.
In the C compiler, add several dependency directories:
6.1 C project properties-> VC++ Directories -> Include Directries -> add $(IFORT_COMPILER19)\compiler\include;
6.2 C project properties-> VC++ Directories -> Libiary Directries -> add $(IFORT_COMPILER19)\compiler\lib; (+\ia32_win or +\intel64_win depend on win32 or X64 compiler used in VS)
In the C linker, add several dependency directories:
7.1 C project properties-> linker-> General-> Additional Dependency Directories->
add C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\lib
(+\x86 or +\x64 depend on win32 or x64 compiler used in VS)
7.2 C project properties-> linker-> General-> Additional Dependency Directories->
add the fortran static library compiled file directory
7.3 C project properties-> linker->input add .lib
In the source code, include the header file with extern ā€œCā€ keyword declaration and call the function
<fortran_subroutine>()
The linker (not the compiler) can't resolve the reference because the naming conventions don't match. You named the C routine "add_" in lowercase and with a trailing underscore. Neither of those are part of the default Intel Fortran conventions.
A second problem is that your directives to export the name into the DLL are outside the routine - they will be ignored. (Not that this matters if you are building a static library.)
The simplest and most portable way to fix this is:
Remove the trailing underscore from add_ in the C source, wherever it appears.
Add BIND(C) at the end of the SUBROUTINE line in the Fortran source.
Move the directives inside the routine.
This will make the names match, not just in Intel Fortran but any other combination of Fortran and C you may use.
I would also recommend replacing the non-standard Fortran variable declarations and use this instead:
REAL(C_DOUBLE) FUNCTION ADD (A, B, C, D) BIND(C)
USE, INTRINSIC :: ISO_C_BINDING
!DEC$ IF DEFINED (_DLL)
!DEC$ ATTRIBUTES DLLEXPORT :: ADD
!DEC$ END IF
REAL(C_DOUBLE) :: B,D
INTEGER(C_INT) :: A,C
...

MKL pardiso on Intel Parallel studio Fortran

Trying to make work MKL_Pardiso on MacOS. I installed Intell Parallel Studio and compile program with fort.
include 'mkl.fi'
INCLUDE 'mkl_pardiso.f90'
program temp
use mkl_pardiso
end program temp
Here is my code to compilier
ifort -mkl temp.f90
The output is
/opt/intel/compilers_and_libraries_2020.1.216/mac/mkl/include/mkl_pardiso.f90(26): error #6218: This statement is positioned incorrectly and/or has syntax errors.
MODULE MKL_PARDISO_PRIVATE
Why does this happen? should I use another flags?
please try build as follows: ifort -mkl mkl_pardiso.f90 temp.f90

How do you run cl.exe from cmd using the same settings as in MSVS?

I have a c++ project in MSVS 2010 Express. I have been planning to write several unit tests to validate this project. Right now they go along the following lines:
#include "header.h" //Header is the header for the source I want to test
void testSomeFunction()
{
//Call function (from external src, prototype in header.h)
//Save output to file
}
int main()
{
testSomeFunction();
return 0;
}
I am creating these source files outside my project because I want to be able to run each of them as individual executable, but I am having trouble getting the Microsoft linker to link them.
This is my problem so far (CMD output):
cl ut_Converter.cpp Converter.obj
ut_Converter.cpp
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xlocale(323) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:ut_Converter.exe
ut_Converter.obj
Converter.obj
Converter.obj : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in ut_Converter.obj
Converter.obj : fatal error LNK1313: pure module detected; cannot link with ijw/native modules
I never really use Microsoft products, I'm familiar with using the GNU tools GCC and make but I have to use the Microsoft tools for this and I have no idea how they work.
Maybe I'm going about building these tests the stupid way but it's the best way I can think of right now.
This is what I want to do:
Compile the source files in my project into object files
Compile my test files into object files
Link the test object file with the appropriate project object files to produce the test executable
How do I go about doing that? (I'm guessing there are some settings I need to set to make everything compatible but I have no idea what they are or how I would go about setting them)
Extra: I know it mentions the debug level but I'd be willing to bet that there will be other incompatible settings. Is there a way to find out what the settings are in the program so I can pass them to cl.exe when I run it?
Edit: When I say command prompt I do mean the one that comes with Visual Studio with all the environment variables setup.
Have you tried going to Programs / Microsoft Visual ... / ... Tools / ... Command Prompt, and running from that dos console window which has the environment variables setup?

How to compile Mathematica to C code with intel C++ compiler (x86) on Win7(x64)ļ¼Ÿ

My OS is windows 7 64bit. I installed Microsoft C++ 2008 Express edition and Intel C++ Compiler v11.1 x86 version.
Now I could successfully compile x86 C code in Mathematica, e.g.
In[1]:= Needs["CCompilerDriver`"]
In[2]:= greeter = CreateExecutable[StringJoin["#include <stdio.h>\n", "int main(){\n", " printf(\"Hello world.\\n\");\n", "}\n"], "hiworld",
"Compiler" -> CCompilerDriver`IntelCompiler`IntelCompiler,
"CompilerInstallation" -> "C:\\Program Files (x86)\\Intel\\Compiler\\11.1\\072\\",
"CompilerName" -> Automatic, "TargetSystemID" -> "Windows"]
Out[2]= "C:\\...\\AppData\\Roaming\\Mathematica\\\
SystemFiles\\LibraryResources\\Windows-x86-64\\hiworld.exe"
But failed to use CompilationTarget -> "C" to compile a function like this
In[3]:= f = Compile[{x, y}, Sqrt[x^2 + y^2], CompilationTarget -> "C"]
During evaluation of In[3]:= LibraryFunction::libload: The function compiledFunction5 was not loaded from the file C:\\...\AppData\Roaming\Mathematica\ApplicationData\CCompilerDriver\BuildFolder\vax-5844\compiledFunction5.dll. >>
During evaluation of In[3]:= Compile::nogen: A library could not be generated from the compiled function. >>
I guess I need to specify a default "TargetSystemID"-> "Windows" since my platform is x64, but don't know how to setting such an option in Mathematica.
Did I miss any point here?
PS: I don't want to install Microsoft Visual Studio recently.
In your first code block you specified the compiler that you wanted. In the second you didn't - so it might be that Mathematica does not "know" about the compilers that you have installed.
Run Needs["CCompilerDriver`"] then CCompilers[Full] to see which of your compilers Mathematica knows about. Also maybe look at the global $CCompilerDirectory.
If your Intel and/or Microsoft compilers are not showing up, then follow the Specific Compilers page of the CCompilerDriver User Guide.
To get your Intel compiler working, I think maybe the following should suffice:
$CCompiler = {
"Compiler" -> CCompilerDriver`IntelCompiler`IntelCompiler,
"CompilerInstallation"->"C:\\Program Files (x86)\\Intel\\Compiler\\11.1\\072\\"}
That said - if I use the above code to change the directory to my compiler to something wrong, then the first error type I get (before the Compile::nogen) is CreateLibrary::instl, not the LibraryFunction::libload message that you have. Maybe something is wrong with your default build directory: $CCompilerDefaultDirectory...
In response to your PS, the Intel C++ v11.1 compiler for Windows is on the list of compilers that they have tested, so you shouldn't need to install MS Visual Studio. On the other hand, you could try GCC for Windows via MiniGW or CygWin (also see SO/187990).

Using Common Header Files in eVC++ 3

I'm learning C++ and i have the eVT(eMbedded Visual Tools) installed in my computer, because of the eVB 3(eMbedded Visual Basic) for my VB pocket programs, but i'm learning C++, then i want to use the eVC++ 3 for develop some command line aplications, then only to test i created an HelloWorld aplication, just for test, but when i try to compile it gave me this error:
Fatal error C1083: Cannot open include file: 'iostream': No such file or directory
Error executing clarm.exe.
Remember that i can't update to eVC++ 4, because i want to build programs for Windows CE 3.1
Thanks!
You need to add the path to the directory where ostream file resides to the list of the compiler include paths (usually -I directive).
Recently i see some eVC++ example and as i can see, eVC++(remember: Plus Plus) only uses C(Without ++) code.