OpenMPI, MPICH et MPI_THREAD_MULTIPLE

Retour à la page Systèmes

Motivation

Une question de développeur arrivée un vendredi soir me laisse le week-end pour trouver la réponse: comment tester si une implémentation MPI peut gérer les threads multiples?

Petit test simple

La norme MPI prévoit, au chapitre C Bindings, une fonction MPI_Init_thread(int *argc, int ***argv, int required,&provided) qui est documentée par exemple dans les pages de manuel MPI.

Cela conduit à un petit programme tout simple:

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

/* This program justs retrieves the level of thread support */
/* for the currently used MPI implementation. */

int main(int argc, char **argv) {
    int provided;
    char *s = NULL;

    MPI_Init_thread(&argc,&argv,MPI_THREAD_MULTIPLE,&provided);

    MPI_Finalize();

    printf("requested=%08x, provided=%08x\n",
        MPI_THREAD_MULTIPLE, provided);


    switch(provided) {
    case MPI_THREAD_SINGLE:
        s = "MPI_THREAD_SINGLE";
        break;
    case MPI_THREAD_FUNNELED:
        s = "MPI_THREAD_FUNNELED";
        break;
    case MPI_THREAD_SERIALIZED:
        s = "MPI_THREAD_SERIALIZED";
        break;
    case MPI_THREAD_MULTIPLE:
        s = "MPI_THREAD_MULTIPLE";
        break;
    } /* switch */

    printf("%s\n",s);

    return provided;
}

Execution de l'exemple

Exemple d'exécution pour deux librairies différentes (OpenMPI et MPich2):

$ module load openmpi-i386
$ mpicc mpi_initthread.c -o mpi_initthread-ompi
$ ./mpi_initthread-ompi
requested=00000003, provided=00000000
MPI_THREAD_SINGLE
$ module switch openmpi-i386 mpich2-i386
$ mpicc mpi_initthread.c -o mpi_initthread-mpich
$ ./mpi_initthread-mpich
requested=00000003, provided=00000003
MPI_THREAD_MULTIPLE