Hello World in MPI

Using MPC to compile and run MPI programs is relatively simple. In most cases, you simply compile your code with the MPC compiler (mpc_cc, mpc_cxx, mpc_f77, etc.).

Here’s our example code: mpi_demo.c

Compile hello_mpi.c

Use the MPC C compiler command, mpc_cc, to compile the MPI code:

mpc_cc mpi_demo.c -o mpi_demo

Execute with mpcrun

Use the mpcrun command to launch the executable:

mpcrun -n=4 ./mpi_demo

You should see output similar to this:

Running MPC with HYDRA job manager
MPC version 2.5.0 C/C++ (4 tasks 1 processes 4 cpus (2.39GHz) ethread_mxn) MPC allocator  none
Initialization time: 0.1s - Memory used: 21MB
MPC OpenMP version 3.1
        Tasking on
        OMP_SCHEDULE 1
        Default #threads (OMP_NUM_THREADS)
        OMP_DYNAMIC 1
        OMP_NESTED 0
        Default #microVPs (OMP_MICROVP_NUMBER)
        OMP_TREE default
        NUMA allocation for tree nodes
#[rank] [runtime] [sort_time] [host] [buffvalue] [nums_sorted]
0 57.5457 25.3636 paratools07.rrp.net 0.099487 50000000
1 60.1933 25.2468 paratools07.rrp.net 0.099487 50000000
3 60.5007 25.3489 paratools07.rrp.net 0.099487 50000000
2 60.537 25.3605 paratools07.rrp.net 0.099487 50000000