Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #5257

ParallelDo and C-compiled routines

From DmitryG <einschlag@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject ParallelDo and C-compiled routines
Date 2011-09-28 06:49 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j5ug1a$7r5$1@smc.vnet.net> (permalink)

Show all headers | View raw


Hi All,

I am going to run several instances of a long calculation on different
cores of my computer and then average the results. The program looks
like this:

SetSharedVariable[Res];
ParallelDo[
 Res[[iKer]] = LongRoutine;
 , {iKer, 1, NKer}]

 LongRoutine is compiled. When compiled in C, it is two times faster
than when compiled in Mathematica. In the case of a Do cycle, this
speed difference can be seen, However, in the case of ParallelDo I
have the speed of the Mathematica-compiled routine independently of
the CompilationTarget in LongRoutine, even if I set NKer=1.

What does it mean? Are routines compiled in C unable of parallel
computing? Or there is a magic option to make them work? I tried
Parallelization->True but there is no result, and it seems this option
is for applying the routine to lists.

Here is an example:
************************************************************
NKer = 1;

(* Subroutine compiled in Mathematica *)
m = Compile[ {{x, _Real}, {n, _Integer}},
   	Module[ {sum, inc}, sum = 1.0; inc = 1.0;
    Do[inc = inc*x/i; sum = sum + inc, {i, n}]; sum]];

(* Subroutine compiled in C *)
c = Compile[ {{x, _Real}, {n, _Integer}},
   	Module[ {sum, inc}, sum = 1.0; inc = 1.0;
    Do[inc = inc*x/i; sum = sum + inc, {i, n}]; sum],
   CompilationTarget -> "C"];

(* There is a difference between Mathematica and C *)
Do[
 Print[AbsoluteTiming[m[1.5, 10000000]][[1]]];
 Print[AbsoluteTiming[c[1.5, 10000000]][[1]]];
 , {iKer, 1, NKer}]
Print[];

(* With ParallelDo there is no difference *)
ParallelDo[
 Print[AbsoluteTiming[m[1.5, 10000000]][[1]]];
 Print[AbsoluteTiming[c[1.5, 10000000]][[1]]];
 , {iKer, 1, NKer}]
**************************************************************

Any help?

Best,

Dmitry

Back to comp.soft-sys.math.mathematica | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

ParallelDo and C-compiled routines DmitryG <einschlag@gmail.com> - 2011-09-28 06:49 +0000
  Re: ParallelDo and C-compiled routines "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-09-29 06:05 +0000
    Re: ParallelDo and C-compiled routines DmitryG <einschlag@gmail.com> - 2011-09-30 08:07 +0000
    Re: ParallelDo and C-compiled routines "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-10-01 07:11 +0000
  Re: ParallelDo and C-compiled routines DmitryG <einschlag@gmail.com> - 2011-09-29 06:09 +0000
  Re: ParallelDo and C-compiled routines Patrick Scheibe <pscheibe@trm.uni-leipzig.de> - 2011-09-30 08:04 +0000
  Re: ParallelDo and C-compiled routines Gabriel Landi <gtlandi@gmail.com> - 2011-10-02 06:39 +0000
  Re: ParallelDo and C-compiled routines Patrick Scheibe <pscheibe@trm.uni-leipzig.de> - 2011-10-03 08:26 +0000
  Re: ParallelDo and C-compiled routines Patrick Scheibe <pscheibe@trm.uni-leipzig.de> - 2011-10-03 08:21 +0000
  Re: ParallelDo and C-compiled routines Gabriel Landi <gtlandi@gmail.com> - 2011-10-03 08:32 +0000

csiph-web