Message Boards Message Boards


Parallel Computing and Object Oriented Programming - Part 1

Posted 1 year ago
1 Reply
3 Total Likes

See Part 2 here:

Wolfram language includes Parallel Computing Tools and the parallel computing is a first step of high-performance computing. A combination of the Parallel Computing Tools and Object Oriented Programming, here after OOP, introduces a new view for the Wolfram language programming. Up to now author had introduced a OOP system for Wolfram language, and now shows an example of OOP based parallel computing.

OOP suits well with the parallel computation because the Instance is basically independent calculation unit and you can find that the same code can apply for both parallel and mono kernel environment.

Part 1 is concerning to the calculation with one instance on one local kernel and the method is explained by an example of Mersenne number calculation. Followings are the Wolfram code steps and you can see first that OOP is composed of basic functions.

step 1; startup local kernels

kernelList = ParallelEvaluate[$KernelID]

step 2; definition of parallel class using instance preceded method

 mq[nam_] := Module[{ins, ine},
     nam[set[{ns_, ne_}]] := {ins, ine} = {ns, ne};
   go[] := Select[Range[ins, ine], PrimeQ[2^# - 1] &]

step 3; definition of object properties with the association list supposing the local kernel number is 4.

object = {
   Association["name" -> Unique[k], "range" -> {9000, 9399}, 
    "kernel" -> kernelList[[1]]],
   Association["name" -> Unique[k], "range" -> {9400, 9699}, 
    "kernel" -> kernelList[[2]]],
   Association["name" -> Unique[k], "range" -> {9700, 9899}, 
    "kernel" -> kernelList[[3]]],
   Association["name" -> Unique[k], "range" -> {9900, 10000}, 
    "kernel" -> kernelList[[4]]

step 4; using the association list, we will construct instances, then set parameters for each instance.

Map[ParallelEvaluate[mq[#name], #kernel] &, object];
Map[ParallelEvaluate[#name[set[#range]], #kernel] &, object]

step 5; execute parallel calculation (this case used Mac 3.4 GHz Intel Core i5)

ts = SessionTime[];
ans = ParallelEvaluate[go[]];
{SessionTime[] - ts, ans}

result is

{10.542539, {{}, {9689}, {}, {9941}}}

To evaluate the result we can compare with a mono-kernel computation.

mono[set[{9000, 10000}]];

ts = SessionTime[];
ans = go[];
{SessionTime[] - ts, ans}

result is

{30.087534, {9689, 9941}}

The parallel computation with 4 local kernels get about 3 times faster than the mono kernel calculation.

Enjoy OOP for Wolfram language.

enter image description here -- you have earned Featured Contributor Badge enter image description here

Your exceptional post has been selected for our editorial column Staff Picks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you, keep it coming, and consider contributing to the The Notebook Archive!

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract