From 9429f6f92d75da698c1ef5cb4a9a579059ecc01c Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Wed, 3 Jul 2024 15:50:32 +0000 Subject: [PATCH] macro --- xprof/sync_daemon_mpi.c | 84 ++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 47 deletions(-) diff --git a/xprof/sync_daemon_mpi.c b/xprof/sync_daemon_mpi.c index 138e3c42..451e59bd 100644 --- a/xprof/sync_daemon_mpi.c +++ b/xprof/sync_daemon_mpi.c @@ -11,62 +11,56 @@ #define RT_SIGNAL_LOCAL_BARRIER SIGRTMIN + 2 #define RT_SIGNAL_FINISH SIGRTMIN + 3 -int MPIX_Init_Session(MPI_Session *lib_shandle, MPI_Comm *lib_comm) { +#define CHECK_MPI(x) \ + do { \ + int retval = (x); \ + if (retval != MPI_SUCCESS) { \ + fprintf(stderr, "Runtime error: %s returned %d at %s:%d", #x, retval, __FILE__, __LINE__); \ + ret = -1; \ + goto fn_exit; \ + } \ + } while (0) - int rc, flag, valuelen; - int ret = MPI_SUCCESS; - const char pset_name[] = "mpi://WORLD"; +int MPIX_Init_Session(MPI_Session *lib_shandle, MPI_Comm *lib_comm) { + /* + * Create session + */ + int ret = 0; const char mt_key[] = "thread_level"; const char mt_value[] = "MPI_THREAD_SINGLE"; - char out_value[100]; /* large enough */ MPI_Group wgroup = MPI_GROUP_NULL; MPI_Info sinfo = MPI_INFO_NULL; MPI_Info tinfo = MPI_INFO_NULL; MPI_Info_create(&sinfo); MPI_Info_set(sinfo, mt_key, mt_value); - rc = MPI_Session_init(sinfo, MPI_ERRORS_RETURN, lib_shandle); - if (rc != MPI_SUCCESS) { - ret = -1; - goto fn_exit; - } + CHECK_MPI(MPI_Session_init(sinfo, MPI_ERRORS_RETURN, lib_shandle)); /* * check we got thread support level foo library needs */ - rc = MPI_Session_get_info(*lib_shandle, &tinfo); - if (rc != MPI_SUCCESS) { - ret = -1; - goto fn_exit; - } - valuelen = sizeof(out_value); - MPI_Info_get_string(tinfo, mt_key, &valuelen, out_value, &flag); - if (flag == 0) { - fprintf(stderr, "THAPI_SYNC_DAEMON_MPI Warning: Could not find key %s\n", mt_key); - //ret = -1; - //goto fn_exit; - } - if (strcmp(out_value, mt_value)) { - fprintf(stderr, "THAPI_SYNC_DAEMON_MPI Warning: Did not get MPI_THREAD_SINGLE, got %s\n", out_value); - //ret = -1; - //goto fn_exit; + CHECK_MPI(MPI_Session_get_info(*lib_shandle, &tinfo)); + { + char out_value[100]; /* large enough */ + int valuelen = sizeof(out_value); + int flag; + CHECK_MPI(MPI_Info_get_string(tinfo, mt_key, &valuelen, out_value, &flag)); + if (flag == 0) + fprintf(stderr, "THAPI_SYNC_DAEMON_MPI Warning: Could not find key %s\n", mt_key); + if (strcmp(out_value, mt_value)) + fprintf(stderr, "THAPI_SYNC_DAEMON_MPI Warning: Did not get MPI_THREAD_SINGLE, got %s\n", + out_value); } /* * create a group from the WORLD process set */ - rc = MPI_Group_from_session_pset(*lib_shandle, pset_name, &wgroup); - - if (rc != MPI_SUCCESS) { - ret = -1; - goto fn_exit; + { + const char pset_name[] = "mpi://WORLD"; + CHECK_MPI(MPI_Group_from_session_pset(*lib_shandle, pset_name, &wgroup)); } /* * get a communicator */ - rc = MPI_Comm_create_from_group(wgroup, "thapi_sync_daemon_mpi", MPI_INFO_NULL, MPI_ERRORS_RETURN, - lib_comm); - if (rc != MPI_SUCCESS) { - ret = -1; - goto fn_exit; - } + CHECK_MPI(MPI_Comm_create_from_group(wgroup, "thapi_sync_daemon_mpi", MPI_INFO_NULL, + MPI_ERRORS_RETURN, lib_comm)); /* * free group, library doesn’t need it. */ @@ -134,23 +128,19 @@ int signal_loop(int parent_pid, MPI_Comm MPI_COMM_WORLD_THAPI, MPI_Comm MPI_COMM int main(int argc, char **argv) { // Initialization - int rc; + int ret = 0; int parent_pid = 0; // World Session and Communicator MPI_Session lib_shandle = MPI_SESSION_NULL; MPI_Comm MPI_COMM_WORLD_THAPI = MPI_COMM_NULL; MPI_Comm MPI_COMM_NODE = MPI_COMM_NULL; - rc = MPIX_Init_Session(&lib_shandle, &MPI_COMM_WORLD_THAPI); - if (rc != MPI_SUCCESS) - goto fn_exit; - rc = MPI_Comm_split_type(MPI_COMM_WORLD_THAPI, MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL, - &MPI_COMM_NODE); - if (rc != MPI_SUCCESS) - goto fn_exit; + CHECK_MPI(MPIX_Init_Session(&lib_shandle, &MPI_COMM_WORLD_THAPI)); + CHECK_MPI(MPI_Comm_split_type(MPI_COMM_WORLD_THAPI, MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL, + &MPI_COMM_NODE)); parent_pid = atoi(argv[1]); - rc = signal_loop(parent_pid, MPI_COMM_WORLD_THAPI, MPI_COMM_NODE); + ret = signal_loop(parent_pid, MPI_COMM_WORLD_THAPI, MPI_COMM_NODE); fn_exit: if (MPI_COMM_NODE != MPI_COMM_NULL) @@ -161,5 +151,5 @@ int main(int argc, char **argv) { MPI_Session_finalize(&lib_shandle); if (parent_pid != 0) kill(parent_pid, RT_SIGNAL_READY); - return rc; + return ret; }