0

I am working on project using MPJ Express. I read here: http://www.researchgate.net/profile/Bryan_Carpenter/publication/221302919_Multicore-enabling_the_MPJ_express_messaging_library/links/02bfe510be4ddbd5d0000000

that for such piece of code:

import mpi.MPI;

public class NumberOfProcesses {

    static int sharedVar = 0;

public static void main(String[] args) throws Exception{

    MPI.Init(args);
    int rank = MPI.COMM_WORLD.Rank();
    sharedVar++;
    System.out.println("Proc <"+rank+">: sharedVar = <"+sharedVar+">");
    MPI.Finalize();
    }
    }



 If we execute the code in the cluster configuration, we observe
    the following output:
    Proc <0>: sharedVar = <1>
    Proc <1>: sharedVar = <1>
    This is the correct and desired output. Here the HelloBug class
    is executed by two MPJ processes in a SPMD fashion. Both of these
    processes execute in a separate JVM and thus do not share the static
    variable sharedVar—for this reason both processes increment the
    variable first and print 1. This execution model is also depicted in
    the Figure 10a.
    On the other hand, when the code is executed in the multicore
    configuration, the following output is observed:
    Proc <0>: sharedVar = <1>
    Proc <1>: sharedVar = <2>

I can't find any way to run the program in multicore configuration. Although it seems to be run in multicore configuration it always gives me on the output such a result:

MPJ Express (0.43) is started in the multicore configuration
Proc <2>: sharedVar = <1>
Proc <1>: sharedVar = <1>
Proc <3>: sharedVar = <1>
Proc <0>: sharedVar = <1>

How to make this piece of code giving on the output sth like that: MPJ Express (0.43) is started in the multicore configuration

Proc <2>: sharedVar = <1>
Proc <1>: sharedVar = <2>
Proc <3>: sharedVar = <3>
Proc <0>: sharedVar = <4>

?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199

1 Answers1

2

The output you provided in both the cases i.e. cluster mode and multicore mode is correct. MPJ Express follows mpiJava standard that enforces communication using message passing even though communicating processes are on same physical machine. So, in MPJ Express multicore configuration there processes would be doing message passing using shared memory mechanism and nothing can be shared between the processes. Imagine that x number (np=x) of java processes are launched on same node and these processes can't share each others variables (static or non-static). If you want to share some variable or data in these java processes then only option is communicate using message passing.

multicore configurations and shared memory are synonyms of each other, reality is, in multicore configuration communication between the processes is done via shared memory instead of using network interface card (NIC) for the sake of better bandwidth.

Ansar
  • 131
  • 3
  • So, referring to this article: http://www.researchgate.net/profile/Bryan_Carpenter/publication/221302919_Multicore-enabling_the_MPJ_express_messaging_library/links/02bfe510be4ddbd5d0000000 How is it possible to get such an output? Proc <2>: sharedVar = <1> Proc <1>: sharedVar = <2> Proc <3>: sharedVar = <3> Proc <0>: sharedVar = <4> – Mateusz Domagała Dec 12 '14 at 14:44