Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to call a C function in parallel through LibraryLink. Here is an example kind of demonstrates that library function can be used in parallel. My question is what happened in the library function call? Does each kernel have its own copy of the library function? Are there some pitfalls we need to watch out when using library functions in parallel?


src = "
  #include \"WolframLibrary.h\"
  #include \"time.h\"

  DLLEXPORT mint WolframLibrary_getVersion(){
    return WolframLibraryVersion;
  DLLEXPORT int WolframLibrary_initialize( WolframLibraryData libData){
    return 0;

  DLLEXPORT int pause(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) {
    return 0;

  void timer(double seconds)
    clock_t x;


test1 = CreateLibrary[src, "test1"];
pauseLib = LibraryFunctionLoad[test1, "pause", {Real}, Integer];

(* {8.021739,Null} *)
(* {2.350266,Null} *)
share|improve this question
Yes, each kernel has its own independent copy of the library function. – Szabolcs Feb 25 '14 at 12:09
I did use LibraryLink functions with the parallel tools. I think there are no pitfalls if you are using LibraryLink (not MathLink). No other pitfalls than those that apply to parallelization in Mathematica in general, at least. The functions will live in separate kernels (separate processes). – Szabolcs Feb 25 '14 at 12:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.