Skip to content

Commit 57e81b6

Browse files
authored
Merge pull request #9 from tomhers/topic/sync_better_error_messages
sync better error messages across all sessions tests
2 parents f90e4b1 + d729041 commit 57e81b6

15 files changed

+410
-280
lines changed

sessions/sessions_test10.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
#include <string.h>
44
#include "mpi.h"
55

6+
void print_error(const char *msg, int rc)
7+
{
8+
char err_str[MPI_MAX_ERROR_STRING];
9+
int resultlen = sizeof(err_str) - 1;
10+
11+
MPI_Error_string(rc, err_str, &resultlen);
12+
fprintf (stderr, "%s return err code = %d (%s)\n", msg, rc, err_str);
13+
}
14+
615
void my_session_errhandler (MPI_Session *foo, int *bar, ...)
716
{
817
fprintf(stderr, "errhandler called with error %d\n", *bar);
@@ -21,26 +30,26 @@ int main (int argc, char *argv[])
2130

2231
rc = MPI_Session_create_errhandler (my_session_errhandler, &errhandler);
2332
if (MPI_SUCCESS != rc) {
24-
fprintf (stderr, "Error handler creation failed with rc = %d\n", rc);
25-
abort ();
33+
print_error("Error handler creation failed", rc);
34+
return -1;
2635
}
2736

2837
rc = MPI_Info_create (&info);
2938
if (MPI_SUCCESS != rc) {
30-
fprintf (stderr, "Info creation failed with rc = %d\n", rc);
31-
abort ();
39+
print_error("Info creation failed", rc);
40+
return -1;
3241
}
3342

3443
rc = MPI_Info_set(info, "mpi_thread_support_level", "MPI_THREAD_MULTIPLE");
3544
if (MPI_SUCCESS != rc) {
36-
fprintf (stderr, "Info key/val set failed with rc = %d\n", rc);
37-
abort ();
45+
print_error("Info key/val set failed", rc);
46+
return -1;
3847
}
3948

4049
rc = MPI_Session_init (info, errhandler, &session);
4150
if (MPI_SUCCESS != rc) {
42-
fprintf (stderr, "Session initialization failed with rc = %d\n", rc);
43-
abort ();
51+
print_error("Session initialization failed", rc);
52+
return -1;
4453
}
4554

4655
rc = MPI_Session_get_num_psets (session, MPI_INFO_NULL, &npsets);
@@ -49,13 +58,12 @@ int main (int argc, char *argv[])
4958
char name[256];
5059
MPI_Session_get_nth_pset (session, MPI_INFO_NULL, i, &psetlen, NULL);
5160
MPI_Session_get_nth_pset (session, MPI_INFO_NULL, i, &psetlen, name);
52-
fprintf (stderr, " PSET %d: %s (len: %d)\n", i, name, psetlen);
5361
}
5462

5563
rc = MPI_Group_from_session_pset (session, "mpi://WORLD", &group);
5664
if (MPI_SUCCESS != rc) {
57-
fprintf (stderr, "Could not get a group for mpi://WORLD. rc = %d\n", rc);
58-
abort ();
65+
print_error("Could not get a group for mpi://WORLD. ", rc);
66+
return -1;
5967
}
6068

6169
MPI_Comm_create_from_group (group, "my_world", MPI_INFO_NULL, MPI_ERRORS_RETURN, &comm_world);
@@ -66,7 +74,6 @@ int main (int argc, char *argv[])
6674

6775
MPI_Comm_free (&comm_world);
6876
MPI_Session_finalize (&session);
69-
printf("Done\n");
7077

7178
MPI_Finalize();
7279

sessions/sessions_test11.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
#include <string.h>
44
#include "mpi.h"
55

6+
void print_error(const char *msg, int rc)
7+
{
8+
char err_str[MPI_MAX_ERROR_STRING];
9+
int resultlen = sizeof(err_str) - 1;
10+
11+
MPI_Error_string(rc, err_str, &resultlen);
12+
fprintf (stderr, "%s return err code = %d (%s)\n", msg, rc, err_str);
13+
}
14+
615
void my_session_errhandler (MPI_Session *foo, int *bar, ...)
716
{
817
fprintf(stderr, "errhandler called with error %d\n", *bar);
@@ -21,26 +30,26 @@ int main (int argc, char *argv[])
2130

2231
rc = MPI_Session_create_errhandler (my_session_errhandler, &errhandler);
2332
if (MPI_SUCCESS != rc) {
24-
fprintf (stderr, "Error handler creation failed with rc = %d\n", rc);
25-
abort ();
33+
print_error("Error handler creation failed", rc);
34+
return -1;
2635
}
2736

2837
rc = MPI_Info_create (&info);
2938
if (MPI_SUCCESS != rc) {
30-
fprintf (stderr, "Info creation failed with rc = %d\n", rc);
31-
abort ();
39+
print_error("Info creation failed", rc);
40+
return -1;
3241
}
3342

3443
rc = MPI_Info_set(info, "mpi_thread_support_level", "MPI_THREAD_MULTIPLE");
3544
if (MPI_SUCCESS != rc) {
36-
fprintf (stderr, "Info key/val set failed with rc = %d\n", rc);
37-
abort ();
45+
print_error("Info key/val set failed", rc);
46+
return -1;
3847
}
3948

4049
rc = MPI_Session_init (info, errhandler, &session);
4150
if (MPI_SUCCESS != rc) {
42-
fprintf (stderr, "Session initialization failed with rc = %d\n", rc);
43-
abort ();
51+
print_error("Session initialization failed", rc);
52+
return -1;
4453
}
4554

4655
rc = MPI_Session_get_num_psets (session, MPI_INFO_NULL, &npsets);
@@ -49,13 +58,12 @@ int main (int argc, char *argv[])
4958
char name[256];
5059
MPI_Session_get_nth_pset (session, MPI_INFO_NULL, i, &psetlen, NULL);
5160
MPI_Session_get_nth_pset (session, MPI_INFO_NULL, i, &psetlen, name);
52-
fprintf (stderr, " PSET %d: %s (len: %d)\n", i, name, psetlen);
5361
}
5462

5563
rc = MPI_Group_from_session_pset (session, "mpi://WORLD", &group);
5664
if (MPI_SUCCESS != rc) {
57-
fprintf (stderr, "Could not get a group for mpi://WORLD. rc = %d\n", rc);
58-
abort ();
65+
print_error("Could not get a group for mpi://WORLD. ", rc);
66+
return -1;
5967
}
6068

6169
MPI_Comm_create_from_group (group, "my_world", MPI_INFO_NULL, MPI_ERRORS_RETURN, &comm_world);
@@ -69,7 +77,6 @@ int main (int argc, char *argv[])
6977
MPI_Finalize();
7078

7179
MPI_Session_finalize (&session);
72-
printf("Done\n");
7380

7481
return 0;
7582
}

sessions/sessions_test12.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
#include <string.h>
44
#include "mpi.h"
55

6+
void print_error(const char *msg, int rc)
7+
{
8+
char err_str[MPI_MAX_ERROR_STRING];
9+
int resultlen = sizeof(err_str) - 1;
10+
11+
MPI_Error_string(rc, err_str, &resultlen);
12+
fprintf (stderr, "%s return err code = %d (%s)\n", msg, rc, err_str);
13+
}
14+
615
void my_session_errhandler (MPI_Session *foo, int *bar, ...)
716
{
817
fprintf(stderr, "errhandler called with error %d\n", *bar);
@@ -19,26 +28,26 @@ int main (int argc, char *argv[])
1928

2029
rc = MPI_Session_create_errhandler (my_session_errhandler, &errhandler);
2130
if (MPI_SUCCESS != rc) {
22-
fprintf (stderr, "Error handler creation failed with rc = %d\n", rc);
23-
abort ();
31+
print_error("Error handler creation failed", rc);
32+
return -1;
2433
}
2534

2635
rc = MPI_Info_create (&info);
2736
if (MPI_SUCCESS != rc) {
28-
fprintf (stderr, "Info creation failed with rc = %d\n", rc);
29-
abort ();
37+
print_error("Info creation failed", rc);
38+
return -1;
3039
}
3140

3241
rc = MPI_Info_set(info, "mpi_thread_support_level", "MPI_THREAD_MULTIPLE");
3342
if (MPI_SUCCESS != rc) {
34-
fprintf (stderr, "Info key/val set failed with rc = %d\n", rc);
35-
abort ();
43+
print_error("Info key/val set failed", rc);
44+
return -1;
3645
}
3746

3847
rc = MPI_Session_init (info, errhandler, &session);
3948
if (MPI_SUCCESS != rc) {
40-
fprintf (stderr, "Session initialization failed with rc = %d\n", rc);
41-
abort ();
49+
print_error("Session initialization failed", rc);
50+
return -1;
4251
}
4352

4453
MPI_Init(&argc, &argv);
@@ -49,13 +58,12 @@ int main (int argc, char *argv[])
4958
char name[256];
5059
MPI_Session_get_nth_pset (session, MPI_INFO_NULL, i, &psetlen, NULL);
5160
MPI_Session_get_nth_pset (session, MPI_INFO_NULL, i, &psetlen, name);
52-
fprintf (stderr, " PSET %d: %s (len: %d)\n", i, name, psetlen);
5361
}
5462

5563
rc = MPI_Group_from_session_pset (session, "mpi://WORLD", &group);
5664
if (MPI_SUCCESS != rc) {
57-
fprintf (stderr, "Could not get a group for mpi://WORLD. rc = %d\n", rc);
58-
abort ();
65+
print_error("Could not get a group for mpi://WORLD. ", rc);
66+
return -1;
5967
}
6068

6169
MPI_Comm_create_from_group (group, "my_world", MPI_INFO_NULL, MPI_ERRORS_RETURN, &comm_world);
@@ -66,7 +74,6 @@ int main (int argc, char *argv[])
6674

6775
MPI_Comm_free (&comm_world);
6876
MPI_Session_finalize (&session);
69-
printf("Done\n");
7077

7178
MPI_Finalize();
7279

sessions/sessions_test13.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
#include <string.h>
44
#include "mpi.h"
55

6+
void print_error(const char *msg, int rc)
7+
{
8+
char err_str[MPI_MAX_ERROR_STRING];
9+
int resultlen = sizeof(err_str) - 1;
10+
11+
MPI_Error_string(rc, err_str, &resultlen);
12+
fprintf (stderr, "%s return err code = %d (%s)\n", msg, rc, err_str);
13+
}
14+
615
void my_session_errhandler (MPI_Session *foo, int *bar, ...)
716
{
817
fprintf(stderr, "errhandler called with error %d\n", *bar);
@@ -19,26 +28,26 @@ int main (int argc, char *argv[])
1928

2029
rc = MPI_Session_create_errhandler (my_session_errhandler, &errhandler);
2130
if (MPI_SUCCESS != rc) {
22-
fprintf (stderr, "Error handler creation failed with rc = %d\n", rc);
23-
abort ();
31+
print_error("Error handler creation failed", rc);
32+
return -1;
2433
}
2534

2635
rc = MPI_Info_create (&info);
2736
if (MPI_SUCCESS != rc) {
28-
fprintf (stderr, "Info creation failed with rc = %d\n", rc);
29-
abort ();
37+
print_error("Info creation failed", rc);
38+
return -1;
3039
}
3140

3241
rc = MPI_Info_set(info, "mpi_thread_support_level", "MPI_THREAD_MULTIPLE");
3342
if (MPI_SUCCESS != rc) {
34-
fprintf (stderr, "Info key/val set failed with rc = %d\n", rc);
35-
abort ();
43+
print_error("Info key/val set failed", rc);
44+
return -1;
3645
}
3746

3847
rc = MPI_Session_init (info, errhandler, &session);
3948
if (MPI_SUCCESS != rc) {
40-
fprintf (stderr, "Session initialization failed with rc = %d\n", rc);
41-
abort ();
49+
print_error("Session initialization failed", rc);
50+
return -1;
4251
}
4352

4453
MPI_Init(&argc, &argv);
@@ -49,13 +58,12 @@ int main (int argc, char *argv[])
4958
char name[256];
5059
MPI_Session_get_nth_pset (session, MPI_INFO_NULL, i, &psetlen, NULL);
5160
MPI_Session_get_nth_pset (session, MPI_INFO_NULL, i, &psetlen, name);
52-
fprintf (stderr, " PSET %d: %s (len: %d)\n", i, name, psetlen);
5361
}
5462

5563
rc = MPI_Group_from_session_pset (session, "mpi://WORLD", &group);
5664
if (MPI_SUCCESS != rc) {
57-
fprintf (stderr, "Could not get a group for mpi://WORLD. rc = %d\n", rc);
58-
abort ();
65+
print_error("Could not get a group for mpi://WORLD. ", rc);
66+
return -1;
5967
}
6068

6169
MPI_Comm_create_from_group (group, "my_world", MPI_INFO_NULL, MPI_ERRORS_RETURN, &comm_world);
@@ -69,7 +77,6 @@ int main (int argc, char *argv[])
6977
MPI_Finalize();
7078

7179
MPI_Session_finalize (&session);
72-
printf("Done\n");
7380

7481
return 0;
7582
}

sessions/sessions_test14.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
#include <string.h>
44
#include "mpi.h"
55

6+
void print_error(const char *msg, int rc)
7+
{
8+
char err_str[MPI_MAX_ERROR_STRING];
9+
int resultlen = sizeof(err_str) - 1;
10+
11+
MPI_Error_string(rc, err_str, &resultlen);
12+
fprintf (stderr, "%s return err code = %d (%s)\n", msg, rc, err_str);
13+
}
14+
615
void my_session_errhandler (MPI_Session *foo, int *bar, ...)
716
{
817
fprintf(stderr, "errhandler called with error %d\n", *bar);
@@ -22,26 +31,26 @@ int main (int argc, char *argv[])
2231

2332
rc = MPI_Session_create_errhandler (my_session_errhandler, &errhandler);
2433
if (MPI_SUCCESS != rc) {
25-
fprintf (stderr, "Error handler creation failed with rc = %d\n", rc);
26-
abort ();
34+
print_error("Error handler creation failed", rc);
35+
return -1;
2736
}
2837

2938
rc = MPI_Info_create (&info);
3039
if (MPI_SUCCESS != rc) {
31-
fprintf (stderr, "Info creation failed with rc = %d\n", rc);
32-
abort ();
40+
print_error("Info creation failed", rc);
41+
return -1;
3342
}
3443

3544
rc = MPI_Info_set(info, "mpi_thread_support_level", "MPI_THREAD_MULTIPLE");
3645
if (MPI_SUCCESS != rc) {
37-
fprintf (stderr, "Info key/val set failed with rc = %d\n", rc);
38-
abort ();
46+
print_error("Info key/val set failed", rc);
47+
return -1;
3948
}
4049

4150
rc = MPI_Session_init (info, errhandler, &session);
4251
if (MPI_SUCCESS != rc) {
43-
fprintf (stderr, "Session initialization failed with rc = %d\n", rc);
44-
abort ();
52+
print_error("Session initialization failed", rc);
53+
return -1;
4554
}
4655

4756
rc = MPI_Session_get_num_psets (session, MPI_INFO_NULL, &npsets);
@@ -50,13 +59,12 @@ int main (int argc, char *argv[])
5059
char name[256];
5160
MPI_Session_get_nth_pset (session, MPI_INFO_NULL, i, &psetlen, NULL);
5261
MPI_Session_get_nth_pset (session, MPI_INFO_NULL, i, &psetlen, name);
53-
fprintf (stderr, " PSET %d: %s (len: %d)\n", i, name, psetlen);
5462
}
5563

5664
rc = MPI_Group_from_session_pset (session, "mpi://WORLD", &group);
5765
if (MPI_SUCCESS != rc) {
58-
fprintf (stderr, "Could not get a group for mpi://WORLD. rc = %d\n", rc);
59-
abort ();
66+
print_error("Could not get a group for mpi://WORLD. ", rc);
67+
return -1;
6068
}
6169

6270
MPI_Comm_create_from_group (group, "my_world", MPI_INFO_NULL, MPI_ERRORS_RETURN, &comm_world);

0 commit comments

Comments
 (0)