Table of Contents

Hello World, MPI & SLURM

Esta guía provee un hello world para MPI y como correrlo usando SLURM.

MPI

hello.cpp
#include <stdio.h>
#include <omp.h>
#include "mpi.h"
 
int main(int argc, char *argv[]) {
 
    MPI_Init(&argc, &argv);
 
    int rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
    char processor_name[MPI_MAX_PROCESSOR_NAME];
    int name_len;
    MPI_Get_processor_name(processor_name, &name_len);
 
    #pragma omp parallel
    {
        int thread_num = omp_get_thread_num();
        printf("Hello from thread %d and process %d on processor %s\n",
               thread_num, rank, processor_name);
    }
 
    MPI_Finalize();
}
Makefile
all: hello-world
 
hello-world: hello-world.cpp
	source $$MODULESHOME/init/bash; module add mpi ; mpic++ hello-world.cpp -o hello-world -fopenmp
 
clean:
	rm -v hello-world

SLURM

Existen diversas maneras para ejecutar trabajos en SLURM, en este caso se dan dos alternativas:

srun

El siguiente comando ejecuta el hello world en la partición tara-2N-1H (-p tara-2N-1H) utilizando 2 nodos (-N 2):

srun -N 2 -p tara-2N-1H hello-world

sbatch

Para correr el hello world usando sbatch es necesario crear el siguiente archivo:

hello-world.sbatch
#!/bin/bash
#
#SBATCH --job-name=mpi-hello-world
#SBATCH --nodes=2
#SBATCH --ntasks=1
#SBATCH --time=1:00
#SBATCH --partition=tara-2N-1H
#SBATCH --output=mpi-hello-world.txt
module load mpi/openmpi
export OMP_NUM_THREADS=2
mpirun hello-world

Para ejecutar el script de sbatch se utiliza:

sbatch hello-world.sbatch