Java as a language for parallel computing. Installation, setup, first program

    Hello,

    I have never seen people writing parallel programs in Java for a certain period of their work with HPC. He wrote something in C, looked at Fortran, but the soul always gravitated to Java. In the end, he sat down and tried to figure it out.

    Content:
    1) MPI for Java implementation; What is it? Where to get?
    2) How to install all this? How to setup?
    3) Let's write our very simplest program. How to run it?


    For an introduction on parallel technologies, you can refer to my previous post .

    1) Implementations of MPI for Java; What is it? Where to get?

    For Java MPI implementations, there are two - mpiJava , as far as I know, already dropped by the author, and MPJ Express, which has in its team the author of mpiJava and several other talented developers. The implementation natively supports two technologies - NIO and Myrinet. Since Myrinet was not at hand, it was tested with NIO. The implementation works like MPICH — daemon processes that talk to each other are created on the right nodes. Implementation

    site . Pretty meager, not enough examples.

    2) How to install all this? How to setup?

    Go. Platform: SuSe 10.3 64-bit on 4 nodes; Java HotSpot (TM) 64-Bit Server VM (build 1.5.0_16-b02, mixed mode).

    // download the 0.35 version because 0.36 is still not running well enough and there are glitches that // resulted in a three-day correspondence with the developer :-). Attention: it is necessary that JVM of the same version be installed on all // nodes!

    wget " sourceforge.net/projects/mpjexpress/files/releases/mpj-v0_35.tar.gz/download "
    tar xvf mpj-v0_35.tar.gz
    cd mpj-v0_35
    ant (if ant is not installed, it should be installed)


    Better everything will happen if the MPJ Express folder is shared in any way to all nodes, so that there is no need to put it along the same path manually.

    Now you need to fix the way. I use ZSH, only the file name differs from Bash.
    The following should be added to the / etc / zshenv file:
    export JAVA_HOME = path_to_java
    export MPJ_HOME = path_to_MPJ
    export PATH = $ PATH: $ MPJ_HOME / bin


    It’s just that it will not work in /.zshrc - it’s necessary that the SSH command also be issued.
    Of course, this must be done on all nodes.

    For convenience, put the most needed library (/path_to_mpj/lib/mpj.jar) in / ext / lib. At all nodes!

    You can try to run demons. Create a machines file, where we specify the necessary nodes:
    node-1
    node-2
    node-3

    and run / path_to_mpj / bin / mpjboot machines - our daemons. You can check the performance right here - if * .pid files were created, one for each daemon, then everything is OK. If you created and disappeared after a couple of seconds, it means problems with the JVM. Not created - no JVM at all. :-) You can diagnose all problems with the help of the utility lying right in the bin - mpjdaemon_linux_x86_64 with the console key.

    Done.

    3) Let's write our very simplest program. How to run it?

    A program is never easier.
    import mpi.*;
    public class HelloWorld {
            public static void main(String args[]) throws Exception {
                      MPI.Init(args);
                      int me = MPI.COMM_WORLD.Rank();
                      int size = MPI.COMM_WORLD.Size();
                      System.out.println("Hello world from <"+me+"> from <"+size);
                      MPI.Finalize();
                   }
    }
    


    Explanations:
    Initialize the parallel section (.Init), create two primitives me & size (node ​​identifier and the number of nodes in the pool), display “Hello world!” and close the parallel section.

    That's all. There will be achievements - I will share. In the meantime, maybe this post has interested someone and a move towards greater achievements.


    Also popular now: