Skip to content

Commit

Permalink
macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Applencourt committed Jul 3, 2024
1 parent 3f3cb2a commit 9429f6f
Showing 1 changed file with 37 additions and 47 deletions.
84 changes: 37 additions & 47 deletions xprof/sync_daemon_mpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}

0 comments on commit 9429f6f

Please sign in to comment.