Make this test capable of running more than "-np 1". If you run with
"-np X", it will launch X parents and then MPI_COMM_SPAWN X additional children. This commit was SVN r13466.
Этот коммит содержится в:
родитель
244fb76002
Коммит
f6e7016cdd
@ -12,17 +12,21 @@ int main(int argc, char* argv[])
|
|||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
MPI_Init(NULL, NULL);
|
MPI_Init(NULL, NULL);
|
||||||
|
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
||||||
|
MPI_Comm_size(MPI_COMM_WORLD, &size);
|
||||||
MPI_Comm_get_parent(&parent);
|
MPI_Comm_get_parent(&parent);
|
||||||
/* If we get COMM_NULL back, then we're the parent */
|
/* If we get COMM_NULL back, then we're the parent */
|
||||||
if (MPI_COMM_NULL == parent) {
|
if (MPI_COMM_NULL == parent) {
|
||||||
pid = getpid();
|
pid = getpid();
|
||||||
printf("Parent [pid %ld] about to spawn!\n", (long)pid);
|
printf("Parent [pid %ld] about to spawn!\n", (long)pid);
|
||||||
MPI_Comm_spawn(argv[0], MPI_ARGV_NULL, 1, MPI_INFO_NULL,
|
MPI_Comm_spawn(argv[0], MPI_ARGV_NULL, size, MPI_INFO_NULL,
|
||||||
0, MPI_COMM_WORLD, &child, MPI_ERRCODES_IGNORE);
|
0, MPI_COMM_WORLD, &child, MPI_ERRCODES_IGNORE);
|
||||||
printf("Parent done with spawn\n");
|
printf("Parent done with spawn\n");
|
||||||
|
if (0 == rank) {
|
||||||
msg = 38;
|
msg = 38;
|
||||||
printf("Parent sending message to child\n");
|
printf("Parent sending message to child\n");
|
||||||
MPI_Send(&msg, 1, MPI_INT, 0, 1, child);
|
MPI_Send(&msg, 1, MPI_INT, 0, 1, child);
|
||||||
|
}
|
||||||
MPI_Comm_disconnect(&child);
|
MPI_Comm_disconnect(&child);
|
||||||
printf("Parent disconnected\n");
|
printf("Parent disconnected\n");
|
||||||
}
|
}
|
||||||
@ -33,8 +37,10 @@ int main(int argc, char* argv[])
|
|||||||
gethostname(hostname, 512);
|
gethostname(hostname, 512);
|
||||||
pid = getpid();
|
pid = getpid();
|
||||||
printf("Hello from the child %d of %d on host %s pid %ld\n", rank, size, hostname, (long)pid);
|
printf("Hello from the child %d of %d on host %s pid %ld\n", rank, size, hostname, (long)pid);
|
||||||
|
if (0 == rank) {
|
||||||
MPI_Recv(&msg, 1, MPI_INT, 0, 1, parent, MPI_STATUS_IGNORE);
|
MPI_Recv(&msg, 1, MPI_INT, 0, 1, parent, MPI_STATUS_IGNORE);
|
||||||
printf("Child %d received msg: %d\n", rank, msg);
|
printf("Child %d received msg: %d\n", rank, msg);
|
||||||
|
}
|
||||||
MPI_Comm_disconnect(&parent);
|
MPI_Comm_disconnect(&parent);
|
||||||
printf("Child %d disconnected\n", rank);
|
printf("Child %d disconnected\n", rank);
|
||||||
}
|
}
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user