Skip to content

Commit 24ca5a2

Browse files
committed
Singleton Spawn tests
Signed-off-by: Joshua Hursey <jhursey@us.ibm.com>
1 parent 684531f commit 24ca5a2

File tree

5 files changed

+121
-0
lines changed

5 files changed

+121
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ collective-big-count/test_scatterv
3434
collective-big-count/*_uniform_count
3535

3636
comm_split_type/cmsplit_type
37+
38+
singleton/hello_c
39+
singleton/simple_spawn
40+
singleton/simple_spawn_multiple

singleton/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
CC=mpicc
2+
CFLAGS=-Wall -g -O0
3+
4+
PROGS=hello_c simple_spawn simple_spawn_multiple
5+
6+
all: $(PROGS)
7+
8+
hello_c: hello_c.c
9+
$(CC) hello_c.c $(CFLAGS) -o hello_c
10+
11+
simple_spawn: simple_spawn.c
12+
$(CC) simple_spawn.c $(CFLAGS) -o simple_spawn
13+
14+
simple_spawn_multiple: simple_spawn_multiple.c
15+
$(CC) simple_spawn_multiple.c $(CFLAGS) -o simple_spawn_multiple
16+
17+
clean:
18+
$(RM) $(PROGS) *.o

singleton/hello_c.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <sys/types.h>
4+
#include <unistd.h>
5+
#include "mpi.h"
6+
7+
int main(int argc, char* argv[])
8+
{
9+
int mcw_rank, mcw_size, len;
10+
char name[MPI_MAX_PROCESSOR_NAME];
11+
12+
MPI_Init(&argc, &argv);
13+
14+
MPI_Comm_rank(MPI_COMM_WORLD, &mcw_rank);
15+
MPI_Comm_size(MPI_COMM_WORLD, &mcw_size);
16+
MPI_Get_processor_name(name, &len);
17+
18+
MPI_Barrier( MPI_COMM_WORLD );
19+
20+
printf("%3d/%3d) [%s] %d Hello, world!\n",
21+
mcw_rank, mcw_size, name, (int)getpid());
22+
fflush(NULL);
23+
24+
MPI_Finalize();
25+
26+
return 0;
27+
}

singleton/simple_spawn.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <mpi.h>
2+
#include <stdio.h>
3+
4+
int main(int argc, char *argv[])
5+
{
6+
MPI_Comm parent, intercomm;
7+
8+
MPI_Init(NULL, NULL);
9+
10+
MPI_Comm_get_parent(&parent);
11+
if (MPI_COMM_NULL != parent)
12+
MPI_Comm_disconnect(&parent);
13+
14+
if (argc > 1) {
15+
printf("Spawning '%s' ... ", argv[1]);
16+
MPI_Comm_spawn(argv[1], MPI_ARGV_NULL,
17+
1, MPI_INFO_NULL, 0, MPI_COMM_SELF,
18+
&intercomm, MPI_ERRCODES_IGNORE);
19+
MPI_Comm_disconnect(&intercomm);
20+
printf("OK\n");
21+
}
22+
23+
MPI_Finalize();
24+
}

singleton/simple_spawn_multiple.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <mpi.h>
2+
#include <stdio.h>
3+
#include <string.h>
4+
5+
int main(int argc, char *argv[])
6+
{
7+
MPI_Comm parent, intercomm;
8+
int maxprocs[2];
9+
char *command[2];
10+
char **spawn_argv[2];
11+
char *argv0[2];
12+
char *argv1[2];
13+
MPI_Info info[2];
14+
15+
MPI_Init(NULL, NULL);
16+
17+
MPI_Comm_get_parent(&parent);
18+
if (MPI_COMM_NULL != parent) {
19+
printf("Hello from a Child (%s)\n", argv[1]);
20+
fflush(NULL);
21+
MPI_Barrier(parent);
22+
MPI_Comm_disconnect(&parent);
23+
}
24+
else if(argc > 1) {
25+
maxprocs[0] = 1;
26+
maxprocs[1] = 2;
27+
command[0] = strdup(argv[1]);
28+
command[1] = strdup(argv[1]);
29+
spawn_argv[0] = argv0;
30+
spawn_argv[1] = argv1;
31+
argv0[0] = strdup("A");
32+
argv0[1] = NULL;
33+
argv1[0] = strdup("B");
34+
argv1[1] = NULL;
35+
info[0] = MPI_INFO_NULL;
36+
info[1] = MPI_INFO_NULL;
37+
38+
printf("Spawning Multiple '%s' ... ", argv[1]);
39+
MPI_Comm_spawn_multiple(2, command, spawn_argv, maxprocs, info,
40+
0, MPI_COMM_SELF,
41+
&intercomm, MPI_ERRCODES_IGNORE);
42+
MPI_Barrier(intercomm);
43+
MPI_Comm_disconnect(&intercomm);
44+
printf("OK\n");
45+
}
46+
47+
MPI_Finalize();
48+
}

0 commit comments

Comments
 (0)