Skip to content

Instantly share code, notes, and snippets.

@bast
Last active August 29, 2015 14:16
Show Gist options
  • Save bast/12f76e73ce3a9506eb8e to your computer and use it in GitHub Desktop.
Save bast/12f76e73ce3a9506eb8e to your computer and use it in GitHub Desktop.
Hello world MPI/OpenMP with Slurm.
Copyright (c) 2015 Radovan Bast
Licensed under the MIT license - http://opensource.org/licenses/MIT
Example source code (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();
}
Example run script (compiles and runs the code):
#!/bin/bash -l
#SBATCH -J hybrid
#SBATCH -t 0:05:00
#SBATCH -n 2
#SBATCH -N 2
#SBATCH --ntasks-per-node=1
#SBATCH -c 32
#SBATCH -e stderr.txt
#SBATCH -o stdout.txt
export OMP_NUM_THREADS=32
CC hello.cpp
aprun -n 2 -N 1 -d 32 -cc none ./a.out > output 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment