Skip to content

Commit

Permalink
Create hybrid.c
Browse files Browse the repository at this point in the history
  • Loading branch information
albeertito7 committed Sep 23, 2021
1 parent d3ca17c commit e198a0c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Hybrid/hybrid.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "stdio.h"
#include "mpi.h"
#include "omp.h"

int main(int argc, char *argv[])
{
int numprocs, rank, namelen;
char processor_name[MPI_MAX_PROCESSOR_NAME];
int iam = 0, np = 1;

MPI_Init(&argc, &argv); // MPI init
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Get_processor_name(processor_name, &namelen);

#pragma omp parallel default(shared) private(iam, np) // OpenMP parallel section
{
np = omp_get_num_threads();
iam = omp_get_thread_num();
printf("Hello from thread %d out of %d from process %d out of %d on %s\n",
iam, np, rank, numprocs, processor_name);
}

MPI_Finalize();
}

/*
* to compile an hybrid program => mpicc -fopenmp hybrid.c -o hybrid
* to execute => via sh script => mpiexec
*/

0 comments on commit e198a0c

Please sign in to comment.