wiki:cypress/Programming/Cexamples/Mpi

MPI C

Hello World

/*
  hello_mpi.c: display a message on the screen
 */
#include <stdio.h>
#include <mpi.h>
 
int main (int argc, char *argv[]) {
  int myid,numproc;
 
  /* Initialize */
  MPI_Init(&argc,&argv);
 
  /* get myid and # of processors */
  MPI_Comm_size(MPI_COMM_WORLD,&numproc);
  MPI_Comm_rank(MPI_COMM_WORLD,&myid);
 
  printf("hello from %d\n", myid);
 
  /* wait until all processors come here */
  MPI_Barrier (MPI_COMM_WORLD);
 
  if ( myid == 0 ) {
    /* only id = 0 do this */
    printf("%d processors said hello!\n",numproc);
  }
 
  MPI_Finalize();
}

Compile

module load intel-psxe
mpicc hello_mpi.c

Example of Jobscript

#!/bin/bash
#SBATCH --job-name=HelloC_MPI
#SBATCH --qos=normal
#SBATCH --time=0-00:10:00
#SBATCH --nodes=4
#SBATCH --ntasks-per-node=1
 
########## THE JOB ITSELF ###########
 
echo Start Job
pwd
echo $SLURM_JOB_NODELIST
echo Number of tasks: $SLURM_NTASKS
 
mpirun ./a.out
 
echo End job
Last modified 3 years ago Last modified on May 23, 2016 1:44:14 PM

Attachments (1)

Download all attachments as: .zip