How do I include mkl_vsl modules for random number generators e.g. 'vsrnggaussian'? (Fortran) - random

I'm new to Fortran (gfortran on windows) and want to use the random number generator vsrnggaussian.
vsrnggaussian needs the Intel MKL VSL modules 'mkl_vsl_type' and 'mkl_vsl' which are provided in the mkl_vsl.f90 file. This file needs to be included to generate the module files 'mkl_vsl_type.mod' and 'mkl_vsl.mod' which are used to process the Fortran use clauses referencing to the VSL interface:
use mkl_vsl_type
use mkl_vsl
I tried multiple things to include the mkl_vsl.f90 file but none of them work:
I inserted the file into the project directory --> 793 errors occured (can't list all of them here in detail) such as:
Unexpected data declaration statement at (1)
[...] at (1) has no implicit type
expecting [...] statement at (1)
unexpected [...] statement at (1)
and finally Fatal Error: Cannot open module file 'mkl_vsl_type.mod' for reading at (1): No such file or directory. compilation terminated. "gfortran -g -o incl_mkl.exe ../incl_mkl.f90" terminated with exit code 1. Build might be incomplete.
I used the full path in the include statement: INCLUDE 'C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2016.1.146/windows/mkl/include/mkl_vsl.f90' --> Error: Can't open included file
I tried the -Idir compiler command: gfortran -I/Program Files (x86)/IntelSWTools/compilers_and_libraries_2016.1.146/windows/mkl/include/ -g -o incl_mkl.exe --> gfortran: error: Files: no such file or directory
I put this into the makefile: INCLUDES=-I. -I/Program Files (x86)/IntelSWTools/compilers_and_libraries_2016.1.146/windows/mkl/include/ --> Error: Can't open included file
How do I include the mkl_vsl.f90 file??
edit: my simple code to include the mkl_vsl.f90 file
(this code will be compiled first before i compile my main code with vsrnggaussian):
Program INCL
IMPLICIT NONE
INCLUDE 'mkl_vsl.f90'
!INCLUDE 'C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2016.1.146/windows/mkl/include/mkl_vsl.f90'
END Program

You'd need to USE both vsl_type and vsl modules. The reason is that the derived types in vsl are defined in vsl_type. MWE
Program INCL
use mkl_vsl_type
use mkl
IMPLICIT NONE
write(6, *) 'hello world'
END Program
You would need to pass the address to file mkl_vsl.f90 to ifort and the mkl flag.
ifort -mkl foo.f90 <address>/mkl_vsl.f90
For using any specific subroutine of MKL consult their website. There is also extensive examples that come with MKL. You may find it in C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2016.1.146/windows/mkl/examples or something like that.

Related

What does this kind of archive file for which has plain text content and a function named INPUT?

I was compiling my rust code with llvm/clang, and some extern libraries were used, so the compiler tried to link them.
But the linker throwed an error: ld.lld: error: /path/to/libwinapi_shcore.a: unknown file type
Then I checked this file and found that it's not like common .a file:
INPUT(
libwinapi_shcore-api-ms-win-shcore-stream-winrt-l1-1-0.a
libwinapi_shcore-api-ms-win-shcore-scaling-l1-1-2.a
libwinapi_shcore-api-ms-win-core-featurestaging-l1-1-0.a
libwinapi_shcore-api-ms-win-shcore-scaling-l1-1-1.a
libwinapi_shcore-api-ms-win-shcore-scaling-l1-1-0.a
libwinapi_shcore-api-ms-win-core-featurestaging-l1-1-1.a
)
What does these mean? Shouldn't .a file be a binary file?

nim: Use a static library

I've tried to get an audio library statically linked to my program. I use this nimble package. To get it run, i had to build the soloud library as described here. For short after download i ran "genie --with-miniaudio-only --platform=x64 vs2017" in the "build" folder and got the source code to generate the dynamic and the static library. For now i can run the following demo program from the nimble package with the generated dll alongside:
import solouddotnim, times, os
var i, spin = 0
var sl : ptr Soloud
sl = Soloud_create()
discard Soloud_init(sl)
Soloud_setGlobalVolume(sl, 1)
var stream = WavStream_create()
discard WavStream_load(cast[ptr Wav](stream), "test.ogg")
let currentTime = epochTime()
let length = WavStream_getLength(stream)
discard Soloud_play(cast[ptr Soloud](sl), cast[ptr Wav](stream))
while epochTime() - currentTime <= length:
sleep(100)
Soloud_deinit(sl)
Soloud_destroy(sl)
Now to the static-link part. In the solouddotnim.nim file of the nimble package i use, i see this part:
when defined(windows):
const
libname* = "libsoloud.dll"
elif ...
So i simple changed the windows part to the following, re-installed the nimble-package and placed the "soloud_static_x64.lib" alongside to the "main.nim" of the testproject:
when defined(windows):
const
libname* = "soloud_static_x64.lib"
elif ...
But this doesent make it. (cant open "soloud_static_x64.lib" error when build)
Evereywhere where the constant "libname" is used there are the pragmas "cdecl", "importc" and "dynlib". For example:
proc Soloud_create*(): ptr Soloud {.cdecl, importc: "Soloud_create", dynlib: libname.}
So "dynlib" is telling nim to use a dll on windows. But was is the pragma for static libraries?
In the nim documentations i only found DynlibOverride to link to static libraries, but i dont understand the example and here is where i stuck. I've tried the followings:
nim c --dynlibOverride:libname --passL:soloud_static_x64.lib "examples\00-ogg\Example00_ogg.nim"
nim c --dynlibOverride:soloudtotnim --passL:soloud_static_x64.lib "examples\00-ogg\Example00_ogg.nim"
Firstly i dont know what parameter dynlibOverride expects and secondly both compiles, but dont work. It expects a dynamic library alongside the exe.
My last try was to remove all dynlib pragmas from the nimble package. But now i cant compile it.
undefined reference to `Soloud_create'
...
Error: execution of an external program failed: 'gcc.exe...
My knowlege ends here. Can someone help me?
Thanks in advance.
Edit:
I could not get any of your solutions work. I break down the problem as small as possible so everybody can reproduce this:
"foo.nim" contains this:
proc add*(a, b: int): int {.cdecl, exportc.} =
a + b
proc sub*(a, b: int): int {.cdecl, exportc.} =
a - b
The .lib is simply generated with this command: "nim c --app:staticlib foo.nim"
Now to use it i created a file "main.nim" with this content:
{.passL:"foo.lib".}
proc add*(a, b: int):int {.cdecl, importc.}
proc sub*(a, b: int):int {.cdecl, importc.}
echo add(10, 5)
echo sub(10, 5)
if i simply build it with "nim c -r main.nim", i get the following output and error:
P:\Nim\LearnCBinding>nim c -r main.nim
Hint: used config file 'C:\nim-1.5.1\config\nim.cfg' [Conf]
Hint: used config file 'C:\nim-1.5.1\config\config.nims' [Conf]
....CC: stdlib_io.nim
CC: stdlib_system.nim
CC: main.nim
Hint: [Link]
foo.lib(#mfoo.nim.c.o):#mfoo.nim.c:(.text+0x1f6): multiple definition of `PreMainInner'
C:\Users\Peter\nimcache\main_d\#mmain.nim.c.o:#mmain.nim.c:(.text+0x120): first defined here
foo.lib(#mfoo.nim.c.o):#mfoo.nim.c:(.text+0x20a): multiple definition of `PreMain'
C:\Users\Peter\nimcache\main_d\#mmain.nim.c.o:#mmain.nim.c:(.text+0x134): first defined here
foo.lib(#mfoo.nim.c.o):#mfoo.nim.c:(.text+0x240): multiple definition of `NimMainInner'
C:\Users\Peter\nimcache\main_d\#mmain.nim.c.o:#mmain.nim.c:(.text+0x16f): first defined here
foo.lib(#mfoo.nim.c.o):#mfoo.nim.c:(.text+0x254): multiple definition of `NimMain'
C:\Users\Peter\nimcache\main_d\#mmain.nim.c.o:#mmain.nim.c:(.text+0x183): first defined here
foo.lib(#mfoo.nim.c.o):#mfoo.nim.c:(.text+0x285): multiple definition of `main'
C:\Users\Peter\nimcache\main_d\#mmain.nim.c.o:#mmain.nim.c:(.text+0x1b4): first defined here
foo.lib(#mfoo.nim.c.o):#mfoo.nim.c:(.text+0x2da): multiple definition of `NimMainModule'
C:\Users\Peter\nimcache\main_d\#mmain.nim.c.o:#mmain.nim.c:(.text+0x209): first defined here
collect2.exe: error: ld returned 1 exit status
Error: execution of an external program failed: 'C:\nim-1.5.1\dist\mingw64\bin\gcc.exe -o P:\Nim\LearnCBinding\main.exe C:\Users\Peter\nimcache\main_d\stdlib_io.nim.c.o C:\Users\Peter\nimcache\main_d\stdlib_system.nim.c.o C:\Users\Peter\nimcache\main_d\#mmain.nim.c.o foo.lib '
Because of the multiple definition error i also tried to build foo.lib with parameter "--noMain:on", but it doesnt make any difference.
Do you have the same problem? By the way i use the current version of Nim "nim-1.5.1" and reinstalled MingW with the finish.exe from nim.
I will try to help you with the following error you have:
undefined reference to `Soloud_create'
but i will assume that you have configured your environment so you can compile your nim programs with visual studio compiler (by adding --cc:vcc to your compile command)
this is because you already seem to have visual studio 2017 and you are compiling soloud static library with it. I think this is the best option when you are compiling with one compiler both: static library and executable that will use it.
open your static library (soloud_static_x64.lib) with some text/hex editor and search for "Soloud_create". i guess you will not find anything. so why is that? because for some reason author decided to not include "C interfacing" in a static library project. so it contains only C++ symbols and not pure C symbols that are needed for our solouddotnim.nim module.
let's try to find out what .cpp file we need for that. i noticed this information on official web site of Soloud - http://sol.gfxile.net/soloud/c_api.html
so i guess we need only one file: soloud_c.cpp
let's try to just include it in SoloudStatic.vcxproj file generated by you with Genie. like this:
..
<ClCompile Include="..\..\src\c_api\soloud_c.cpp">
</ClCompile>
..
and recompile our static library. i use this command in powershell:
& 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\MSBuild.exe' /p:PlatformToolset=v142`;WindowsTargetPlatformVersion=10`;Configuration=Release`;Platform=x64 .\SoloudStatic.vcxproj
but you can compile how you want. just make sure that it's architecture is really x64. you can check it with this command:
dumpbin /headers soloud_static_x64.lib | more
finally just link it with your nim file. add this line to the top:
{.link:"soloud_static_x64.lib".}
and compile nim file with this command:
nim c --cc:vcc --dynlibOverride:libsoloud.dll -r "examples\00-ogg\Example00_ogg.nim"

`Can't open module file, No such file or directory` when compiling Fortran with an external library

I am currently trying to compile a Fortran 90 code using a module that is supposed to be in a dynamic library libfckit.so. So far my code is:
program debug
use fckit_mpi_module
end program debug
And for the compilation step I use the following command:
mpifc -I/path/to/the/lib debug_fckit.f90 -o debug_fckit.exe
I get the following error:
use fckit_mpi_module
1
Fatal Error: Can't open module file ‘fckit_mpi_module.mod’ for reading at (1): No such file or directory
I know that this is a common error in Fortran, I searched google but I did not find any satisfying solution for my case.
Thank you Vladimir and Evets for your comments that helped me to fix the issue. I just added the paths to the directories where the module fckit_mpi_module.mod and the library libfckit.so are. So now my command for compiling the code reads:
mpifc -I/path/to/the/directory/where/the/module/fckit_mpi_module.mod/is -l/path/to/the/directory/where/the/library/lifckit.so/is debug.fckit.f90 -o debug_fckit
Hope this helps some other noobie like me.

erlang debug_info option - inside module or during compilation?

After overcoming some troubles with installation I tried to use erlang debugger on simple module:
I included -compile([debug_info]). option in source file and compiled with:
1> c(test_module).
This did not work as expected: After running
2> debugger:start().
the monitor window appeared, then I clicked
Module->Interpret...->test_module.erl
and got error
"Error when interpreting: test_module.erl: No debug_info in BEAM file".
Deleting -compile([debug_info]). line and changing
1> c(test_module).
to
1> c(test_module, [debug_info]).
solved the problem.
What is the difference between these two ways of setting compilation option, why one works and the other does not?
According to the docs, the two ways should be equivalent:
Note that all the options except the include path ({i,Dir}) can also
be given in the file with a -compile([Option,...]). attribute.
(From Erlang -- compile doc)
Check this question for more info.

GHC :: Linking agains sqlite3 fails on Windows

I created simple application, which uses sqlite3 as it's datastore back-end. I faced no problems when building and running it on Linux, but after I tried to build it on Windows, I see weird linking error:
Linking dist\build\hnotes\hnotes.exe ...
C:\Documents and Settings\Admin\Application Data\cabal\sqlite-0.5.2.2\ghc-7.0.4/libHSsqlite-0.5.2.2.
a(sqlite3-local.o):sqlite3-local.c:(.text+0x21): undefined reference to `sqlite3_temp_directory'
C:\Documents and Settings\Admin\Application Data\cabal\sqlite-0.5.2.2\ghc-7.0.4/libHSsqlite-0.5.2.2.
a(sqlite3-local.o):sqlite3-local.c:(.text+0x40): undefined reference to `sqlite3_temp_directory'
collect2: v ld 1
cabal.EXE: Error: some packages failed to install:
hnotes-0.1 failed during the building phase. The exception was:
ExitFailure 1
What may be wrong there? I suspect that qalite3.dll has to be added to linking stage, but have no idea how to do that. Adding --extra-lib-dirs=path-to-sqlite-dll doesn't help either (perhaps because I need to update my cabal file somehow, to support this?).
Not sure if It's a bug or not, but the error comes from the sqlite3.h include of the sqlite package.
A look in the file shows this
/*
** CAPI3REF: Name Of The Folder Holding Temporary Files {H10310} <S20000>
**
** If this global variable is made to point to a string which is
** the name of a folder (a.k.a. directory), then all temporary files
** created by SQLite will be placed in that directory. If this variable
** is a NULL pointer, then SQLite performs a search for an appropriate
** temporary file directory.
**
** It is not safe to modify this variable once a [database connection]
** has been opened. It is intended that this variable be set once
** as part of process initialization and before any SQLite interface
** routines have been call and remain unchanged thereafter.
*/
SQLITE_EXTERN char *sqlite3_temp_directory;
so it's declared as an extern. So simple test:
module Main where
import Database.SQLite
main
= do hwd <- openConnection "test"
closeConnection hwd
putStrLn "done"
This crashes during linking as expected with the error you have above.
So I created a small C test file foo.c
#include "sqlite-0.5.2.2\\include\\sqlite3-local.h"
char* sqlite3_temp_directory = "C:\\test2";
So I'm defining a temp_directory and then I pass the c file along during compilation of the haskell source
$ ghc test.hs foo.c
[1 of 1] Compiling Main ( test.hs, test.o )
Linking test.exe ...
and then running it also returns the expected result
$ ./test
done
So it seems that you just need to give a value for the sqlite3_temp_directory, which if you set it to a NULL pointer will use the TMP/TEMP etc variables as defined in the SQLLITE manual.
edit, follow up on why it worked on Linux but not on windows
In the sqlite package, there's a file sqlite3.c under the folder sqlite3.6. This provides a bunch of defaults for the sqlite package.
when on linux OS_UNIX is defined and when on linux it uses the defines under OS_WIN.
The function we're interested in is the function which sets the temporary directory. for unix this'll be unixGetTempname and for windows winGetTempname.
If you look at the implementation of both these functions, for the unix one it has list of directories that it'll try
static const char *azDirs[] = {
0,
"/var/tmp",
"/usr/tmp",
"/tmp",
".",
};
it tries to access them in order and the one it can write to it uses to generate a temporary folder in.
For windows however one of the first lines are:
if( sqlite3_temp_directory ){
sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
}else if( isNT() ){
so for windows sqlite3_temp_directory is actually used. This is why it doesn't compile if It can't find it.

Resources