[Date Index]
[Thread Index]
[Author Index]
Re: Listable parallel basic LibraryLink dll
*To*: mathgroup at smc.vnet.net
*Subject*: [mg122498] Re: Listable parallel basic LibraryLink dll
*From*: Patrick Scheibe <pscheibe at trm.uni-leipzig.de>
*Date*: Sun, 30 Oct 2011 04:22:15 -0500 (EST)
*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com
*References*: <201110251018.GAA05905@smc.vnet.net>
Hi,
I think this is currently not possible.
But one can of course investigate a bit how Mathematica does it.
In the following I talk exclusively about compiled functions having
CompilationTarget->"C" and my system is Linux which may behave very
differently.
1. When you use compile and build two versions of your function, one
that's normal and one that's parallelized and listable, and you used
then ExportString[func,"C"] on these you'll see, that the c-code is the
same. Therefore, it seems not to be possible to export this behaviour
into c-code.
2. On the other hand, if you have a compiled function, you could use
InputForm on the listable function to see how it looks inside. For a
simple dummy function this looks on my Linux box like this here:
CompiledFunction[{8, 8., 5852}, {_Real}, {{3, 0, 0}, {3, 0, 1}},
{{1, {2, 0, 0}}}, {0, 1, 5, 0, 0}, {{40, 1, 3, 0, 0, 3, 0, 1},
{40, 56, 3, 0, 0, 3, 0, 2}, {10, 0, 3}, {13, 3, 0, 3},
{40, 58, 3, 0, 3, 3, 0, 4}, {19, 4, 3}, {13, 1, 2, 3, 1}, {1}},
Function[{x}, Sin[x] + x^2 - 1/(1 + x), Listable], Evaluate,
LibraryFunction["/home/patrick/.Mathematica/ApplicationData/CCompilerDriver
/BuildFolder/warp-4499/compiledFunction1.so", "compiledFunction1",
{{Real, 0, "Constant"}}, Real]]
"compiledFunction1.so" is the parallel version, so lets keep this
library and load it later by hand. I moved it to another location (when
you close a kernel, all created library-code is deleted) and loaded it
on a fresh kernel with
f = LibraryFunctionLoad["compiledFunction1",
"compiledFunction1", {{Real, 0, "Constant"}}, Real]
what I got was a listable, parallelized function
CompiledFunction[{x}, Sin[x] + x^2 - 1/(1 + x), -CompiledCode -]
which suggests that (1) the c-library code is aware of the general
analytic expression. Therefore, you could call f[t^2] and get the
correct result. (2) The listable attribute and the parallelization go
indeed into to library.
3. To check what happens when you really call the compiled function I
used "ltrace" (if you're with Bill Gates, you may not know this) and
listed all functions of all (sytem-)libraries which were used during the
call.
Comparing the results for a parallel and a serial call brought up this
line to my attention, which appeared in the parallel call but not in the
serial:
8 pthread_cond_wait
It says that this function was called 8 times and happy enough I have
exactly 8 cores which were used in the parallel call.
For all these reasons I think we can assume the following. The
parallelization and the listable attribute, as well as the analytic
expression go into the c-library if you use Compile. It seems not
possible to get this behaviour by exporting c-code and I did'nt find
documentation which explains how to write a library-function which is
listable and parallelized.
BUT, you can of course write your own parallel function with OpenMP,
TBB, or whatever you prefer and call it.
Cheers
Patrick
On Tue, 2011-10-25 at 06:18 -0400, Rui wrote:
> I've just started with LibraryLink. I'm actually mostly interested in getting the basics so I can start leaning while I use it.
> I could get some basic C++ code of mine to link well with Mathematica.
>
> Do you know how to make it behave like a CompiledFunction with the Listable attribute and parallelization set to True?
>
> Thanks
>
Prev by Date:
**Re: PopupMenu Problems**
Next by Date:
**Re: List plot with random size for each point**
Previous by thread:
**Listable parallel basic LibraryLink dll**
Next by thread:
**Another basic (?) question about RecurrenceTable and replacement**
| |