// mpi_spawn.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include "mpi.h" #define NHOST 2 int main(int argc, char* argv[]) { int supported; int rank, size; MPI_Comm parent, intercomm; MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &supported); if(supported != MPI_THREAD_MULTIPLE){ printf("The library does not support MPI_THREAD_MULTIPLE\n"); exit(-1); } MPI_Comm_get_parent(&parent); if (parent == MPI_COMM_NULL){ int i; int nproc[NHOST] = {1, 1}; //char* progs[NHOST] = {"c:\\mpi_spawn", "c:\\tm\\mpi_spawn"}; char* progs[NHOST] = {"c:\\mpi_spawn", "c:\\mpi_spawn"}; MPI_Info infos[NHOST]; for (i=0; i < NHOST; i++) { MPI_Info_create(&infos[i]); MPI_Info_set(infos[i], "host", "localhost"); } MPI_Comm_spawn_multiple(NHOST, progs, MPI_ARGVS_NULL, nproc, infos, 0, MPI_COMM_WORLD, &intercomm, MPI_ERRCODES_IGNORE); for (i=0; i < NHOST; i++) { MPI_Info_free(&infos[i]); } } else{ intercomm = parent; } MPI_Comm_rank(intercomm, &rank); MPI_Comm_size(intercomm, &size); printf("[%d/%d] Hello world\n", rank, size); fflush(stdout); MPI_Comm_free(&intercomm); MPI_Finalize(); return 0; }