Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Compilation options question
Replies: 3   Last Post: Jan 23, 2011 5:36 AM

 Messages: [ Previous | Next ]
 Ramiro Posts: 26 Registered: 9/18/07
Compilation options question
Posted: Jan 21, 2011 4:32 AM

Hello,

I have successfully compiled the main parts of my program and runs
much faster than before. I do have a question. Consider the
following 4 examples, all compiled programs but with different
options. Example0 is just plain compile, example1 has what I thought
would be the optimal: parallelization and compilationtarget->"C" and
declaration of the return types for the external calls, but it takes
twice as long!!! Why is that?

If I remove the declaration of the return types it goes a bit faster
than plain Compile even though it has parallelization and
CompilationTarget-> "C", and if I remove CompilationTarget-> "C" it's

Any insight? Thanks so much to everyone for their help with Compile,
my MCMC simulations will be much faster now.

Ramiro

p.s. My main program is basically multiplying the function in question
(exampleN) many many times, that's why I put multiply over the same
call.

In[170]:=
example0 =
Compile[{{n, _Real, 1}, {a, _Real}, {b, _Real}, {t, _Real, 1}},
With[{tn = Total[n]},
b^a*Exp[LogGamma[
tn + a] - (Total[LogGamma[n + 1]] + LogGamma[a]) +
Total[n*Log[t]] - (tn + a)*Log[Total[t] + b]]]];
Times @@ Table[
example0[{1, 1, 1, 1}, 1, 1, {3, 3, 3, 3}], {i,
10000}] // AbsoluteTiming

Out[171]= {0.210959, 6.2372127891421*10^-22811}

In[172]:=
example1 =
Compile[{{n, _Real, 1}, {a, _Real}, {b, _Real}, {t, _Real, 1}},
With[{tn = Total[n]},
b^a*Exp[LogGamma[
tn + a] - (Total[LogGamma[n + 1]] + LogGamma[a]) +
Total[n*Log[t]] - (tn + a)*
Log[Total[t] +
b]]], {{LogGamma[_], _Real}, {Total[_], _Real}},
Parallelization -> True, CompilationTarget -> "C"];
Times @@ Table[
example1[{1, 1, 1, 1}, 1, 1, {3, 3, 3, 3}], {i,
10000}] // AbsoluteTiming

Out[173]= {0.414509, 6.2372127890803*10^-22811}

In[174]:=
example2 =
Compile[{{n, _Real, 1}, {a, _Real}, {b, _Real}, {t, _Real, 1}},
With[{tn = Total[n]},
b^a*Exp[LogGamma[
tn + a] - (Total[LogGamma[n + 1]] + LogGamma[a]) +
Total[n*Log[t]] - (tn + a)*Log[Total[t] + b]]],
Parallelization -> True, CompilationTarget -> "C"];
Times @@ Table[
example2[{1, 1, 1, 1}, 1, 1, {3, 3, 3, 3}], {i,
10000}] // AbsoluteTiming

Out[175]= {0.188601, 6.2372127890803*10^-22811}

In[176]:=
calculatePoissonsGamma =
Compile[{{n, _Real, 1}, {a, _Real}, {b, _Real}, {t, _Real, 1}},
With[{tn = Total[n]},
b^a*Exp[LogGamma[
tn + a] - (Total[LogGamma[n + 1]] + LogGamma[a]) +
Total[n*Log[t]] - (tn + a)*Log[Total[t] + b]]],
Parallelization -> True];
Times @@ Table[
calculatePoissonsGamma[{1, 1, 1, 1}, 1, 1, {3, 3, 3, 3}], {i,
10000}] // AbsoluteTiming

Out[177]= {0.219753, 6.2372127891421*10^-22811}

Date Subject Author
1/21/11 Ramiro
1/22/11 Daniel Lichtblau
1/23/11 Oliver Ruebenkoenig
1/23/11 Ray Koopman