Differences between OMP and MPI libraries in parallel programming

What is the difference between the library of OMP and MPI of C ? If both are for parallel computation programs

 1
Author: Santi92, 2015-12-06

2 answers

The main differs from this in the architecture of the parallel system: MPI is used for systems of distributed memory

enter the description of the image here

While OMP is used in systems of shared memory OMP architecture

Process communication in MPI is through message passing, while in OMP communication between processes is not necessary, since all threads they share memory. OMP helps parallelize a program, by means of directives:

  • omp_get_num_threads ()
  • omp_get_thread_num ()

Many of these are environment variables that are set to compile time. While in MPI the programmer is primarily responsible for parallelizing the program by using the following functions:

  • MPI_Init ()
  • MPI_Comm_rank (MPI_COMM_WORLD, & rank);
  • MPI_Comm_size (MPI_COMM_WORLD, &size);
  • MPI_Finalize ()

Below I leave two sensillos examples:

OpenMP Implementation

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

int main(){
  int nthreads, tid;
#pragma omp parallel private(nthreads,tid)
{
  tid = omp_get_thread_num();

  printf("Hola Mundo. Soy el hilo %d\n", tid);
  if (tid==0){
      nthreads = omp_get_num_threads();
      printf("Número de hilos: %d\n",nthreads);
  }

}
  return 0;
}

MPI implementation:

#include <stdio.h>
#include <mpi.h>
int main (int argc, char **argv)
{
  int rank;
  int size;
  MPI_Init (&argc, &argv);
  MPI_Comm_rank (MPI_COMM_WORLD, &rank);
  MPI_Comm_size (MPI_COMM_WORLD, &size);
  printf ("Soy el nodo %d de un cluster de %d\n", rank, size);
  MPI_Finalize ();
  return 0;
}
 4
Author: Santi92, 2015-12-06 18:41:01

To complement, in MPI the programmer takes care of all the logistics of how the communications will be while in OpenMP not. Additionally, depending on the MPI implementation, there are functions that work with shared memory as OpenMP does.

 0
Author: Daniel Burbano, 2017-06-30 22:02:34