I've been working on a project for quite a long time, and now when I finally want to use it in praxis I don't know how.
I have created a shared library (libcwv.so) with a header (cwv.so) with nvidia's nvcc. To use the library, one does not need any compiler from CUDA. Hence, I want to use the usual LibraryFunctionLoad in Mathematica for it. Before I post the code, this is the function I want to use in Mathematica:
int timeEvolution(vector<double> times, vector<double> startVector, double deltaE, vector<int> columnIndices, vector<double> nonZeroValues, vector<int> rowPointers, int timeChop, int dimChop, double* RefinalVector, double* ImfinalVector)
Since I haven't even managed to include the c++ vector library, I have also built a wrapper:
int timeEvolution(double* times, double* startVector, double deltaE, int* columnIndices, double* nonZeroValues, int* rowPointers, int timeChop, int dimChop, double* RefinalVector, double* ImfinalVector)
The wrapper contains pointers instead of vectors, and I have already been able to include it:
#include "WolframLibrary.h"
DLLEXPORT mint WolframLibrary_getVersion(){
return WolframLibraryVersion;
}
DLLEXPORT int WolframLibrary_initialize( WolframLibraryData libData) {
return 0;
}
DLLEXPORT void WolframLibrary_uninitialize(WolframLibraryData libData) {
return;
}
#include "cwv.h"
DLLEXPORT double testFunc(WolframLibraryData libData,
double Argc, MArgument *Args, MArgument Res) {
MArgument_setReal(Res, MArgument_getReal(Args[0])+1);
return LIBRARY_NO _ERROR;
}
The code above successfully compiles via CreateLibrary. Hence, I have managed to at very least include this function. But now is when the trouble begins.
The function timeEvolution modifies the entries of the last two arguments. Those will be the results. It returns 0 if it succeeds, and it returns 1 if it fails. Now I want to create a Mathematica function whose arguments shall be lists as well as real and integer numbers. In the end, I want it to return the two last arguments of timeEvolution as lists. Those entries (RefinalVector and Imfinalvector) can contain anything. They will be overwritten. But they should have a definite size. I will solve the problem with the size on my own. For now let it just be a global constant called "S".
I have made several attempts so far to somehow use my function, but none has lead to any result, yet. Also I don't find any useful results on the internet. (Maybe I'm just too clueless; I'm not exactly an expert with Mathematica)
My questions are therfore:
1. How do I include vectors (#include<vector>
) in C++ code for CreateLibrary in Mathematica? (It just tells me that it cannot be found)
2. How do I pass over a set of arguments consisting of lists, reals and integers to a C++ function and call every single one of them individually?
3. Could you give me an example (or at least an idea) of how to use my function in Mathematica?
I know that I'm asking for almost everything and cannot offer anything in return. But I have really tried to find sources explaining how to do this, and I've failed. So please, if anyone knows what to do, be so kind and help me solve this :)
(I have to apologize in advance, because I probably won't be able to read your answers before Monday. Afterwards I will definitely appreciate every help!)
double Argc
should bemint Argc
. That's a very important difference. Your questions: 1. Don't type the code in a Mathematica string. That method only supports C code. Put it in a separate file if you need C++. 2. I don't understand this question. $\endgroup$MTensor
) to do this. Take a look at the examples that work with tensors. $\endgroup$