MPI Hybrid Example

// hybrid.c

#include <stdio.h> #include "mpi.h" #include <omp.h>

int main(int argc, char *argv[]) { int num_procs, myid, tid;

// Initialize MPI MPI_Init(&argc, &argv);

//get input params int nthreds = atoi(argv[1]);

//set num threads omp_set_num_threads(nthreds);

// Obtain the number of processes MPI_Comm_size(MPI_COMM_WORLD, &num_procs);

// Obtain the process id MPI_Comm_rank(MPI_COMM_WORLD, &myid); #pragma omp parallel private(tid) { tid = omp_get_thread_num(); printf("\nHello, from processor %d at thred %d\n", myid, tid); }

MPI_Finalize(); }