Supponendo che abbia una buona ragione per fare quanto segue (penso di avere), come farlo funzionare?mpi multiple init finalizza
#include "mpi.h"
int main(int argc, char *argv[])
{
int myid, numprocs;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
// ...
MPI_Finalize();
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
// ...
MPI_Finalize();
return 0;
}
ho ottenuto l'errore:
--------------------------------------------------------------------------
Calling any MPI-function after calling MPI_Finalize is erroneous.
The only exceptions are MPI_Initialized, MPI_Finalized and MPI_Get_version.
--------------------------------------------------------------------------
*** An error occurred in MPI_Init
*** after MPI was finalized
*** MPI_ERRORS_ARE_FATAL (your MPI job will now abort)
[ange:13049] Abort after MPI_FINALIZE completed successfully; not able to guarantee that all other processes were killed!
Il motivo per farlo:
ho Python avvolgimento intorno codice C++. Alcune classi wrapper hanno un costruttore che chiama MPI_Init e un distruttore che chiama MPI_Finalize. Mi piacerebbe essere in grado in Python di creare liberamente, cancellare ricreare l'oggetto Python che avvolge questa classe C++. L'obiettivo finale è creare un webservice interamente in Python, che importa una volta l'estensione Python C++ ed esegue un codice Python in base alla richiesta dell'utente.
EDIT: Penso che rifatterò il codice C++ per dare possibilità a non MPI_Init e MPI_Finalize in costruttore e distruttore, quindi è possibile farlo esattamente una volta nello script Python (usando mpi4py).