Skip to content

Commit aa5d113

Browse files
authored
Merge pull request #7 from tomhers/topic/sessions_test
add new sessions tests to main repo
2 parents 49a98d9 + 8761627 commit aa5d113

18 files changed

+1870
-2
lines changed

sessions/Makefile

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,32 @@ EXAMPLES = \
3737
sessions_ex2 \
3838
sessions_ex3 \
3939
sessions_ex4 \
40-
sessions_test
40+
sessions_test \
41+
sessions_test1 \
42+
sessions_test2 \
43+
sessions_test3 \
44+
sessions_test4 \
45+
sessions_test5 \
46+
sessions_test6 \
47+
sessions_test7 \
48+
sessions_test8 \
49+
sessions_test9 \
50+
sessions_test10 \
51+
sessions_test11 \
52+
sessions_test12 \
53+
sessions_test13 \
54+
sessions_test14 \
55+
sessions_test15 \
56+
sessions_test16
4157

4258

4359
# Default target. Always build the C MPI examples. Only build the
4460
# others if we have the appropriate Open MPI / OpenSHMEM language
4561
# bindings.
4662

47-
all: sessions_ex1.o sessions_ex2 sessions_test
63+
all: sessions_ex1.o sessions_ex2 sessions_test sessions_test1 sessions_test2 sessions_test3 sessions_test4 sessions_test5 \
64+
sessions_test6 sessions_test7 sessions_test8 sessions_test9 sessions_test10 sessions_test11 sessions_test12 sessions_test13 \
65+
sessions_test14 sessions_test15 sessions_test16
4866
@ if which ompi_info >/dev/null 2>&1 ; then \
4967
$(MAKE) mpi; \
5068
fi
@@ -75,4 +93,37 @@ sessions_ex4: sessions_ex4.f90
7593
$(MPIFC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
7694
sessions_test: sessions_test.c
7795
$(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
96+
sessions_test1: sessions_test1.c
97+
$(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
98+
sessions_test2: sessions_test2.c
99+
$(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
100+
sessions_test3: sessions_test3.c
101+
$(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
102+
sessions_test4: sessions_test4.c
103+
$(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
104+
sessions_test5: sessions_test5.c
105+
$(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
106+
sessions_test6: sessions_test6.c
107+
$(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
108+
sessions_test7: sessions_test7.c
109+
$(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
110+
sessions_test8: sessions_test8.c
111+
$(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
112+
sessions_test9: sessions_test9.c
113+
$(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
114+
sessions_test10: sessions_test10.c
115+
$(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
116+
sessions_test11: sessions_test11.c
117+
$(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
118+
sessions_test12: sessions_test12.c
119+
$(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
120+
sessions_test13: sessions_test13.c
121+
$(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
122+
sessions_test14: sessions_test14.c
123+
$(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
124+
sessions_test15: sessions_test15.c
125+
$(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
126+
sessions_test16: sessions_test16.c
127+
$(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
128+
78129

sessions/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,39 @@ prte --daemonize --system-server
140140
prun -n 4 --system-server-first (additional arguments)
141141
```
142142

143+
## Test documentation
144+
145+
sessions_test1: Initialize one session, finalize that sessions, then initialize another session
146+
147+
sessions_test2: Initialize two sessions and perform operations with each session simultaneously, then finalize both sessions
148+
149+
sessions_test3: Try to make a group from an invalid pset (should fail)
150+
151+
sessions_test4: Try to make a group from a pset using MPI_GROUP_NULL (should fail)
152+
153+
sessions_test5: Initialize two sessions, perform functions with one session and finalize that session, then perform functions with the other session after the first has been finalized
154+
155+
sessions_test6: Same as sessions_test1 but with the sessions using different names
156+
157+
sessions_test7: Initialize two sessions, perform operations with one and finalize it, then perform operations with the other and finalize it
158+
159+
sessions_test8: Initialize two sessions, create one comm in each, and compare them (should fail because objects from different sessions shall not be intermixed with each other in a single MPI procedure call per the MPI standard)
160+
161+
sessions_test9: Initialize the World model and Sessions model, make a comm using the sessions and split it, then make an intercomm using the split comm from the session and MPI_COMM_WORLD (should fail because MPI objects derived from the Sessions model shall not be intermixed in a single MPI
162+
procedure call with MPI objects derived from the World model per the MPI standard)
163+
164+
sessions_test10: Initialize World model, initialize Sessions model, finalize Sessions model, finalize World model
165+
166+
sessions_test11: Initialize World model, initialize Sessions model, finalize World model, finalize Sessions model
167+
168+
sessions_test12: Initialize Sessions model, initialize World model, finalize Sessions model, finalize World model
169+
170+
sessions_test13: Initialize Sessions model, initialize World model, finalize World model, finalize Sessions model
171+
172+
sessions_test14: Initialize a session, create a comm, then try to use that comm with a comm from MPI_Comm_get_parent (should fail because MPI objects derived from the Sessions Model shall not be intermixed in a single MPI procedure call with MPI objects derived from the communicator obtained from a call to MPI_COMM_GET_PARENT or MPI_COMM_JOIN)
173+
174+
sessions_test15: Initialize two sessions, create MPI_Requests using comms from different sessions, then include MPI_Requests from different sessions in one call to each of the following functions: MPI_Waitall(), MPI_Waitsome(), MPI_Waitany(), MPI_Testall(), MPI_Testsome(), and MPI_Testany()
175+
176+
sessions_test16: Initialize a sessions, create a comm from the session, then attempt to access the values of the default attributes usually attached to MPI_COMM_WORLD (MPI_TAG_UB, MPI_HOST, MPI_IO, and MPI_WTIME_IS_GLOBAL). Per the MPI Standard, only the MPI_TAG_UB attribute should be accessible when using the Sessions model.
177+
143178

sessions/sessions_test1.c

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include "mpi.h"
5+
6+
void my_session_errhandler (MPI_Session *foo, int *bar, ...)
7+
{
8+
fprintf(stderr, "errhandler called with error %d\n", *bar);
9+
}
10+
11+
int main (int argc, char *argv[])
12+
{
13+
MPI_Session session, session1;
14+
MPI_Errhandler errhandler;
15+
MPI_Group group;
16+
MPI_Comm comm_world, comm_self;
17+
MPI_Info info;
18+
int rc, npsets, one = 1, sum, i;
19+
20+
rc = MPI_Session_create_errhandler (my_session_errhandler, &errhandler);
21+
if (MPI_SUCCESS != rc) {
22+
fprintf (stderr, "Error handler creation failed with rc = %d\n", rc);
23+
abort ();
24+
}
25+
26+
rc = MPI_Info_create (&info);
27+
if (MPI_SUCCESS != rc) {
28+
fprintf (stderr, "Info creation failed with rc = %d\n", rc);
29+
abort ();
30+
}
31+
32+
rc = MPI_Info_set(info, "mpi_thread_support_level", "MPI_THREAD_MULTIPLE");
33+
if (MPI_SUCCESS != rc) {
34+
fprintf (stderr, "Info key/val set failed with rc = %d\n", rc);
35+
abort ();
36+
}
37+
38+
rc = MPI_Session_init (info, errhandler, &session);
39+
if (MPI_SUCCESS != rc) {
40+
fprintf (stderr, "Session initialization failed with rc = %d\n", rc);
41+
abort ();
42+
}
43+
44+
rc = MPI_Session_get_num_psets (session, MPI_INFO_NULL, &npsets);
45+
for (i = 0 ; i < npsets ; ++i) {
46+
int psetlen = 0;
47+
char name[256];
48+
MPI_Session_get_nth_pset (session, MPI_INFO_NULL, i, &psetlen, NULL);
49+
MPI_Session_get_nth_pset (session, MPI_INFO_NULL, i, &psetlen, name);
50+
fprintf (stderr, " PSET %d: %s (len: %d)\n", i, name, psetlen);
51+
}
52+
53+
rc = MPI_Group_from_session_pset (session, "mpi://WORLD", &group);
54+
if (MPI_SUCCESS != rc) {
55+
fprintf (stderr, "Could not get a group for mpi://WORLD. rc = %d\n", rc);
56+
abort ();
57+
}
58+
59+
MPI_Comm_create_from_group (group, "my_world", MPI_INFO_NULL, MPI_ERRORS_RETURN, &comm_world);
60+
MPI_Group_free (&group);
61+
62+
MPI_Allreduce (&one, &sum, 1, MPI_INT, MPI_SUM, comm_world);
63+
64+
fprintf (stderr, "World Comm Sum (1): %d\n", sum);
65+
66+
rc = MPI_Group_from_session_pset (session, "mpi://SELF", &group);
67+
if (MPI_SUCCESS != rc) {
68+
fprintf (stderr, "Could not get a group for mpi://SELF. rc = %d\n", rc);
69+
abort ();
70+
}
71+
72+
MPI_Comm_create_from_group (group, "myself", MPI_INFO_NULL, MPI_ERRORS_RETURN, &comm_self);
73+
MPI_Group_free (&group);
74+
MPI_Allreduce (&one, &sum, 1, MPI_INT, MPI_SUM, comm_self);
75+
76+
fprintf (stderr, "Self Comm Sum (1): %d\n", sum);
77+
78+
MPI_Errhandler_free (&errhandler);
79+
MPI_Info_free (&info);
80+
81+
82+
MPI_Comm_free (&comm_world);
83+
MPI_Comm_free (&comm_self);
84+
MPI_Session_finalize (&session);
85+
printf("Finished first finalize\n");
86+
87+
rc = MPI_Session_create_errhandler (my_session_errhandler, &errhandler);
88+
if (MPI_SUCCESS != rc) {
89+
fprintf (stderr, "Error handler creation failed with rc = %d\n", rc);
90+
abort ();
91+
}
92+
93+
rc = MPI_Info_create (&info);
94+
if (MPI_SUCCESS != rc) {
95+
fprintf (stderr, "Info creation failed with rc = %d\n", rc);
96+
abort ();
97+
}
98+
99+
rc = MPI_Info_set(info, "mpi_thread_support_level", "MPI_THREAD_MULTIPLE");
100+
if (MPI_SUCCESS != rc) {
101+
fprintf (stderr, "Info key/val set failed with rc = %d\n", rc);
102+
abort ();
103+
}
104+
105+
printf("Starting second init\n");
106+
rc = MPI_Session_init (info, errhandler, &session);
107+
printf("Finished second init\n");
108+
if (MPI_SUCCESS != rc) {
109+
fprintf (stderr, "Session initialization failed with rc = %d\n", rc);
110+
abort ();
111+
}
112+
113+
rc = MPI_Session_get_num_psets (session, MPI_INFO_NULL, &npsets);
114+
for (i = 0 ; i < npsets ; ++i) {
115+
int psetlen = 0;
116+
char name[256];
117+
MPI_Session_get_nth_pset (session, MPI_INFO_NULL, i, &psetlen, NULL);
118+
MPI_Session_get_nth_pset (session, MPI_INFO_NULL, i, &psetlen, name);
119+
fprintf (stderr, " PSET %d: %s (len: %d)\n", i, name, psetlen);
120+
}
121+
122+
rc = MPI_Group_from_session_pset (session, "mpi://WORLD", &group);
123+
if (MPI_SUCCESS != rc) {
124+
fprintf (stderr, "Could not get a group for mpi://WORLD. rc = %d\n", rc);
125+
abort ();
126+
}
127+
128+
MPI_Comm_create_from_group (group, "my_world", MPI_INFO_NULL, MPI_ERRORS_RETURN, &comm_world);
129+
MPI_Group_free (&group);
130+
131+
MPI_Allreduce (&one, &sum, 1, MPI_INT, MPI_SUM, comm_world);
132+
133+
fprintf (stderr, "World Comm Sum (1): %d\n", sum);
134+
135+
136+
rc = MPI_Group_from_session_pset (session, "mpi://SELF", &group);
137+
if (MPI_SUCCESS != rc) {
138+
fprintf (stderr, "Could not get a group for mpi://SELF. rc = %d\n", rc);
139+
abort ();
140+
}
141+
142+
MPI_Comm_create_from_group (group, "myself", MPI_INFO_NULL, MPI_ERRORS_RETURN, &comm_self);
143+
MPI_Group_free (&group);
144+
MPI_Allreduce (&one, &sum, 1, MPI_INT, MPI_SUM, comm_self);
145+
146+
fprintf (stderr, "Self Comm Sum (1): %d\n", sum);
147+
148+
MPI_Errhandler_free (&errhandler);
149+
MPI_Info_free (&info);
150+
151+
152+
MPI_Comm_free (&comm_world);
153+
MPI_Comm_free (&comm_self);
154+
MPI_Session_finalize (&session);
155+
156+
return 0;
157+
}

sessions/sessions_test10.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include "mpi.h"
5+
6+
void my_session_errhandler (MPI_Session *foo, int *bar, ...)
7+
{
8+
fprintf(stderr, "errhandler called with error %d\n", *bar);
9+
}
10+
11+
int main (int argc, char *argv[])
12+
{
13+
MPI_Session session;
14+
MPI_Errhandler errhandler;
15+
MPI_Group group;
16+
MPI_Comm comm_world;
17+
MPI_Info info;
18+
int rc, npsets, one = 1, sum, i;
19+
20+
MPI_Init(&argc, &argv);
21+
22+
rc = MPI_Session_create_errhandler (my_session_errhandler, &errhandler);
23+
if (MPI_SUCCESS != rc) {
24+
fprintf (stderr, "Error handler creation failed with rc = %d\n", rc);
25+
abort ();
26+
}
27+
28+
rc = MPI_Info_create (&info);
29+
if (MPI_SUCCESS != rc) {
30+
fprintf (stderr, "Info creation failed with rc = %d\n", rc);
31+
abort ();
32+
}
33+
34+
rc = MPI_Info_set(info, "mpi_thread_support_level", "MPI_THREAD_MULTIPLE");
35+
if (MPI_SUCCESS != rc) {
36+
fprintf (stderr, "Info key/val set failed with rc = %d\n", rc);
37+
abort ();
38+
}
39+
40+
rc = MPI_Session_init (info, errhandler, &session);
41+
if (MPI_SUCCESS != rc) {
42+
fprintf (stderr, "Session initialization failed with rc = %d\n", rc);
43+
abort ();
44+
}
45+
46+
rc = MPI_Session_get_num_psets (session, MPI_INFO_NULL, &npsets);
47+
for (i = 0 ; i < npsets ; ++i) {
48+
int psetlen = 0;
49+
char name[256];
50+
MPI_Session_get_nth_pset (session, MPI_INFO_NULL, i, &psetlen, NULL);
51+
MPI_Session_get_nth_pset (session, MPI_INFO_NULL, i, &psetlen, name);
52+
fprintf (stderr, " PSET %d: %s (len: %d)\n", i, name, psetlen);
53+
}
54+
55+
rc = MPI_Group_from_session_pset (session, "mpi://WORLD", &group);
56+
if (MPI_SUCCESS != rc) {
57+
fprintf (stderr, "Could not get a group for mpi://WORLD. rc = %d\n", rc);
58+
abort ();
59+
}
60+
61+
MPI_Comm_create_from_group (group, "my_world", MPI_INFO_NULL, MPI_ERRORS_RETURN, &comm_world);
62+
MPI_Group_free (&group);
63+
64+
MPI_Errhandler_free (&errhandler);
65+
MPI_Info_free (&info);
66+
67+
MPI_Comm_free (&comm_world);
68+
MPI_Session_finalize (&session);
69+
printf("Done\n");
70+
71+
MPI_Finalize();
72+
73+
return 0;
74+
}

0 commit comments

Comments
 (0)