MPI Hello World

This is an openmpi example using the module openmpi/gcc on the Typhon cluster:

$> cat hello.c
#include <mpi.h>
#include <stdio.h>

int main(int argc, char** argv) {
    MPI_Init(NULL, NULL);
    int world_size;
    MPI_Comm_size(MPI_COMM_WORLD, &world_size);
    int world_rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
    char processor_name[MPI_MAX_PROCESSOR_NAME];
    int name_len;
    MPI_Get_processor_name(processor_name, &name_len);
    printf("Hello world from processor %s, rank %d"
            " out of %d processors\n",
            processor_name, world_rank, world_size);
    MPI_Finalize();
}

# Load module and compile
$>module load openmpi/gcc
$>mpicc mpi_hello.c -o mpi_hello

# This is an example submit script for mpi_hello
$>cat mpi_hello.sh
#!/bin/bash
#SBATCH --nodes=2
#SBATCH --ntasks-per-node=12
#SBATCH --time=5:00

module load openmpi/gcc
srun ./mpi_hello

# Submit the mpi_hello.sh script
$>sbatch mpi_hello.sh

# After the job completes you can find the output in the file slurm-$jobNumber if you did not specify a name.
$>cat slurm-<jobid>.out
MPIHello running on 24 processors.
Greetings from processor 0, on host typhon-node1.sns.ias.
Greetings from processor 1, on host typhon-node1.sns.ias.
Greetings from processor 2, on host typhon-node1.sns.ias.
Greetings from processor 3, on host typhon-node1.sns.ias.
Greetings from processor 4, on host typhon-node1.sns.ias.
Greetings from processor 5, on host typhon-node1.sns.ias.
Greetings from processor 6, on host typhon-node1.sns.ias.
Greetings from processor 7, on host typhon-node1.sns.ias.
Greetings from processor 8, on host typhon-node1.sns.ias.
Greetings from processor 9, on host typhon-node1.sns.ias.
Greetings from processor 10, on host typhon-node1.sns.ias.
Greetings from processor 11, on host typhon-node1.sns.ias.
Greetings from processor 12, on host typhon-node2.sns.ias.
Greetings from processor 13, on host typhon-node2.sns.ias.
Greetings from processor 14, on host typhon-node2.sns.ias.
Greetings from processor 15, on host typhon-node2.sns.ias.
Greetings from processor 16, on host typhon-node2.sns.ias.
Greetings from processor 17, on host typhon-node2.sns.ias.
Greetings from processor 18, on host typhon-node2.sns.ias.
Greetings from processor 19, on host typhon-node2.sns.ias.
Greetings from processor 20, on host typhon-node2.sns.ias.
Greetings from processor 21, on host typhon-node2.sns.ias.
Greetings from processor 22, on host typhon-node2.sns.ias.
Greetings from processor 23, on host typhon-node2.sns.ias.