繁体   English   中英

MPJ Java多核配置还是共享内存?

[英]MPJ Java multicore configuration or shared memory?

我正在使用MPJ Express进行项目。 我在这里阅读: http : //www.researchgate.net/profile/Bryan_Carpenter/publication/221302919_Multicore-enabling_the_MPJ_express_messaging_library/links/02bfe510be4ddbd5d0000000

对于这样的一段代码:

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>

我找不到以多核配置运行程序的任何方法。 尽管它似乎是在多核配置中运行的,但它总是在输出中给我这样的结果:

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>

如何使这段代码像这样输出:MPJ Express(0.43)在多核配置中启动

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

您在两种情况下(即集群模式和多核模式)提供的输出都是正确的。 MPJ Express遵循mpiJava标准,即使通信进程在同一台物理计算机上,该标准也使用消息传递来强制进行通信。 因此,在MPJ Express多核配置中,进程将使用共享内存机制进行消息传递,并且进程之间无法共享任何内容。 想象一下,在同一节点上启动了x个(np = x) Java进程 ,并且这些进程不能共享彼此的变量 (静态或非静态)。 如果要在这些Java进程中共享一些变量或数据,则只有选项是使用消息传递进行通信

多核配置和共享内存是彼此的同义词,现实是,在多核配置中,进程之间的通信是通过共享内存而不是为了获得更好的带宽而使用网络接口卡(NIC)进行的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM