I compiled ADDA on Windows using Visual Studio 2019 from the sources, without using the provided makefiles.
For the C/C++ project, I started from the "C/C++ Console Application" example project in Visual Studio 2019, selecting the Intel C++ Compiler 2024 and the Base Platform Toolset v142. I added the additional option "-Qstd=c99". I included the ADDA C/C++ source files in the project, excluding the files associated with OpenCL, namely "oclcore.c" and "oclmatvec.c".
During compilation, I encountered a small error in "param.c". With the options used in my project, the "_isatty" function is not defined in the <io.h> header but in the <corecrt_io.h> header. Therefore, I added the following to the "param.c" code:
#ifdef WINDOWS
#include <corecrt_io.h>
#endif
For the Fortran project, I started from the "Fortran DLL" example project in Visual Studio 2019, selecting the Intel IFX compiler. I added the ".f" and ".f90" source files. The compilation produces a dynamic library ".dll" and its import file ".lib" that must be used for linking the C/C++ executable. I chose to compile the Fortran code into a DLL to simplify linking. Indeed, on Windows, the code in a DLL contains all the libraries used by the DLL. Therefore, it is not necessary to add the Fortran libraries for linking the C/C++ project. Moreover, a DLL compiled with IFX can be used by a C/C++ code compiled with a GNU compiler (gcc or g++).
To create the Fortran DLL, I encountered two small issues. In a DLL project compiled with IFX, you need to explicitly indicate which functions should be exported. Therefore, I modified the headers of "bessel.f90" and "propaesplibreintadda.f" as follows:
!DEC$ ATTRIBUTES DLLEXPORT :: BJNDD
subroutine BJNDD ( n, x, bj, dj, fj )
........
!DEC$ ATTRIBUTES DLLEXPORT :: propaespacelibreintadda
subroutine propaespacelibreintadda(Rij,k0a,
..........
Moreover, for DLLs compiled with IFX, the names of the exported functions are always in uppercase, and there is no addition of the underscore ("_") character. To use the Fortran functions from the C/C++ code, you need to modify the names used in the C/C++ code accordingly.
To access the Fortran DLL functions with minimal modification to the ADDA C/C++ code, I used wrappers:
void PROPAESPACELIBREINTADDA(const double *Rij,const double *ka,const double *gridspacex,const double *gridspacey,
const double *gridspacez,const double *relreq,double *result,int *ifail);
void propaespacelibreintadda_(const double* Rij, const double* ka, const double* gridspacex, const double* gridspacey,
const double* gridspacez, const double* relreq, double* result, int* ifail) {
PROPAESPACELIBREINTADDA(Rij,ka,gridspacex,gridspacey,
gridspacez,relreq,result,ifail);
};
void BJNDD(const int* n, const double* x, double* bj, double* dj, double* fj);
void bjndd_(const int* n, const double* x, double* bj, double* dj, double* fj) {
BJNDD(n, x, bj, dj, fj);
};
The construction of ADDA can be done without difficulty after adding the FFTW DLLs and their import libraries. The preprocessor options for the C/C++ code are:
If you need to add specific preprocessor options, please provide them, and I can include them in the translation.
_CRT_SECURE_NO_WARNINGS
NO_GITHASH
_WIN32
My computer has an NVIDIA GTX 760 graphics card with CUDA 11.4 installed, so I also compiled ADDA_OCL with Visual Studio 2019. The construction of the project is very similar to that of ADDA. Of course, you need to add the "oclcore.c" and "oclmatvec.c" source files and remove "matvec.c".
The compilation options for the C/C++ code are:
_CRT_SECURE_NO_WARNINGS
NO_GITHASH
_WIN32
OPENCL
OCL_READ_SOURCE_RUNTIME
SIZET_ULONG
Here is the continuation of the translation:
I encountered a small error in "oclcore.c" because UINT32_MAX and UINT64_MAX are not defined in <io.h> but in <stdint.h>.
Therefore, I added the following lines to the "oclcore.c" code:
#ifdef WINDOWS
#include<stdint.h>
#endif
I also encountered another error at runtime during the compilation of the last line of "
oclkernels.cl", where the characters encountered did not seem to be UTF-8 characters.
I did not understand the meaning of this error, which seems to occur when reading the "
oclkernels.cl" file. To solve this problem, I modified the reading of the "
oclkernels.cl" file by using a "readKernelSource" function that I created. The code became:
// Read the kernel source from the file
size_t kernelSize;
char* cSourceString = readKernelSource("
oclkernels.cl", &kernelSize);
cl_program program = clCreateProgramWithSource(context, 1, (const char**)&cSourceString, (const size_t*)&kernelSize, &err);
Here is the continuation of the translation with the code for the "readKernelSource" function:
The code for the "readKernelSource" function is:
//-------------------------------------------------------
char* readKernelSource(const char* filename, size_t* size) {
FILE* fp = fopen(filename, "r");
if (!fp) {
fprintf(stderr, "Failed to load kernel.\n");
exit(1);
}
fseek(fp, 0, SEEK_END);
*size = ftell(fp);
rewind(fp);
char* source = (char*)malloc(*size + 1);
fread(source, 1, *size, fp);
source[*size] = '\0';
fclose(fp);
return source;
}
//------------------------------------------------
To build the program, you need to add the OpenCL headers: #include <CL/cl.h> and the library "openCL.lib". These files can be found by downloading one of the OpenCL projects from Nvidia, for example, "oclVectorAdd.zip" from this link: "
https://developer.nvidia.com/opencl"
To build the program, you also need to add the headers and libraries associated with "clFFT". The "clFFT" code can be obtained from GitHub:
https://github.com/clMathLibraries/clFFT. The useful headers are located on GitHub in the subdirectory "clFFT-master\src\include". The libraries can be compiled from the "CMakeLists.txt" file using CMake or CLion. I performed this compilation by selecting the Microsoft compiler from Visual Studio 2019 in CMake or CLion. The necessary libraries for compiling ADDA_OCL with Visual Studio 2019 are "clFFT.lib" and "StatTimer.lib" as well as the DLLs "clFFT.dll" and "StatTimer.dll".
Best Regards
Michel Gross