MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Mathematica 7 is now available

  • To: mathgroup at smc.vnet.net
  • Subject: [mg94077] Re: Mathematica 7 is now available
  • From: Jon Harrop <jon at ffconsultancy.com>
  • Date: Thu, 4 Dec 2008 07:15:22 -0500 (EST)
  • References: <gg62p3$56g$1@smc.vnet.net>

Alexei Boulbitch wrote:
> Dear MatheGroup members,
> 
> I would like to put a trivial though an important question to you. For
> some time I try to find problems to be best solved* using Mathematica, and
> where parallel computing would be necessary. So far I did not succeed in
> finding them. This tells me that I do not understand something
> important... 

Parallelism is used when performance is important. In general, Mathematica
is used when performance is largely unimportant. Consequently, they are
almost mutually exclusive.

For example, you would need to parallelize the following Mathematica program
perfectly across 700,000 CPU cores to obtain performance comparable to the
equivalent OCaml program:

delta = Sqrt[$MachineEpsilon];

RaySphere[o_, d_, c_, r_] :=
  Block[{v, b, disc, t1, t2},
    v = c - o;
    b = v.d;
    disc = Sqrt[b^2 - v.v + r^2];
    t2 = b + disc;
    If[Im[disc] != 0 || t2 <= 0, \[Infinity],
      t1 = b - disc;
      If[t1 > 0, t1, t2]]
    ]

Intersect[o_, d_][{lambda_, n_}, Sphere[c_, r_]] :=
 Block[{lambda2 = RaySphere[o, d, c, r]},
  If[lambda2 >= lambda, {lambda, n}, {lambda2, 
    Normalize[o + lambda2 d - c]}]
  ]
Intersect[o_, d_][{lambda_, n_}, Bound[c_, r_, s_]] :=
 Block[{lambda2 = RaySphere[o, d, c, r]},
  If[lambda2 >= lambda, {lambda, n}, 
   Fold[Intersect[o, d], {lambda, n}, s]]
  ]

neglight = N@Normalize[{1, 3, -2}];

nohit = {\[Infinity], {0, 0, 0}};

RayTrace[o_, d_, scene_] :=
 Block[{lambda, n, g, p},
  {lambda, n} = Intersect[o, d][nohit, scene];
  If[lambda == \[Infinity], 0,
   g = n.neglight;
   If[g <= 0, 0,
    {lambda, n} = 
     Intersect[o + lambda d + delta n, neglight][nohit, scene];
    If[lambda < \[Infinity], 0, g]]]
  ]

Create[level_, c_, r_] :=
 Block[{obj = Sphere[c, r]},
  If[level == 1, obj,
   Block[{a = 3*r/Sqrt[12], Aux},
    Aux[x1_, z1_] := Create[level - 1, c + {x1, a, z1}, 0.5 r];
    Bound[c, 
     3 r, {obj, Aux[-a, -a], Aux[a, -a], Aux[-a, a], Aux[a, a]}]]]]

scene = Create[1, {0, -1, 4}, 1];

Main[level_, n_, ss_] :=
 Block[{scene = Create[level, {0, -1, 4}, 1]},
  Table[
   Sum[
     RayTrace[{0, 0, 0}, 
      N@Normalize[{(x + s/ss/ss)/n - 1/2, (y + Mod[s, ss]/ss)/n - 1/2,
          1}], scene], {s, 0, ss^2 - 1}]/ss^2, {y, 0, n - 1},
   {x, 0, n - 1}]]

AbsoluteTiming[Export["image.pgm", Graphics@Raster@Main[9, 512, 4]]]

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?u


  • Prev by Date: Re: easier method for Flatten[Position[list2,x_x...??
  • Next by Date: RE: Dynamic Show in Manipulate
  • Previous by thread: Re: How to substitute a function?
  • Next by thread: Re: Mathematica 7 is now available