Skip to content

Commit

Permalink
ML: Issue 3565
Browse files Browse the repository at this point in the history
Fix to allow user-supplied MPI_Comm in the C-API.
  • Loading branch information
rhoope committed Oct 17, 2018
1 parent 8d56e74 commit c17aa9e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
15 changes: 12 additions & 3 deletions packages/ml/src/Comm/ml_comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ ML_Comm *global_comm = NULL; /* should not be used to avoid side effect */
/* -------------------------------------------------------------------- */

int ML_Comm_Create( ML_Comm ** com )
{
#ifdef ML_MPI
return ML_Comm_Create2(com, MPI_COMM_WORLD);
#else
return ML_Comm_Create2(com, 0);
#endif
}

int ML_Comm_Create2( ML_Comm ** com, USR_COMM in_comm )
{
ML_Comm *com_ptr;

Expand All @@ -36,13 +45,13 @@ int ML_Comm_Create( ML_Comm ** com )
com_ptr->USR_cheapwaitbytes = ML_Comm_CheapWait;

#ifdef ML_MPI
MPI_Comm_size(MPI_COMM_WORLD, &(com_ptr->ML_nprocs));
MPI_Comm_rank(MPI_COMM_WORLD, &(com_ptr->ML_mypid));
MPI_Comm_size(in_comm, &(com_ptr->ML_nprocs));
MPI_Comm_rank(in_comm, &(com_ptr->ML_mypid));
com_ptr->USR_sendbytes = ML_Comm_Send;
com_ptr->USR_irecvbytes = ML_Comm_Irecv;
com_ptr->USR_waitbytes = ML_Comm_Wait;
com_ptr->USR_cheapwaitbytes = ML_Comm_CheapWait;
com_ptr->USR_comm = MPI_COMM_WORLD;
com_ptr->USR_comm = in_comm;
#ifdef ML_CATCH_MPI_ERRORS_IN_DEBUGGER
/* register the error handling function */
ML_Comm_ErrorHandlerCreate((USR_ERRHANDLER_FUNCTION *) ML_Comm_ErrorHandler,
Expand Down
1 change: 1 addition & 0 deletions packages/ml/src/Comm/ml_comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ extern "C"
#endif

extern int ML_Comm_Create( ML_Comm ** comm );
extern int ML_Comm_Create2( ML_Comm ** comm, USR_COMM com );
extern int ML_Comm_Destroy( ML_Comm ** comm );
extern int ML_Comm_Check( ML_Comm *comm );

Expand Down
11 changes: 10 additions & 1 deletion packages/ml/src/Main/ml_struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ ML_PrintControl ML_PrintLevel = {0};

int ml_defines_have_printed = 0;
int ML_Create(ML **ml_ptr, int Nlevels)
{
#ifdef ML_MPI
return ML_Create2(ml_ptr, Nlevels, MPI_COMM_WORLD);
#else
return ML_Create2(ml_ptr, Nlevels, 0);
#endif
}

int ML_Create2(ML **ml_ptr, int Nlevels, USR_COMM in_comm)
{
int i, length;
double *max_eigen;
Expand Down Expand Up @@ -77,7 +86,7 @@ int ML_Create(ML **ml_ptr, int Nlevels)
(*ml_ptr)->repartitionStartLevel = -1;
(*ml_ptr)->RAP_storage_type=ML_MSR_MATRIX;

ML_Comm_Create( &((*ml_ptr)->comm) );
ML_Comm_Create2( &((*ml_ptr)->comm), in_comm );
if (global_comm == NULL)
global_comm = (*ml_ptr)->comm;

Expand Down
8 changes: 8 additions & 0 deletions packages/ml/src/Main/ml_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,21 @@ extern ML_PrintControl ML_PrintLevel;
/* ******************************************************************** */
/* ******************************************************************** */

#ifdef ML_MPI
#include "mpi.h"
#define USR_COMM MPI_Comm
#else
#define USR_COMM int
#endif

#ifndef ML_CPP
#ifdef __cplusplus
extern "C" {
#endif
#endif

extern int ML_Create(ML **ml, int Nlevels);
extern int ML_Create2(ML **ml, int Nlevels, USR_COMM comm);
extern int ML_build_ggb( ML *ml, void *data);
extern void ML_build_ggb_cheap(ML *ml, void *data);
extern void ML_build_ggb_fat(ML *ml, void *data);
Expand Down

0 comments on commit c17aa9e

Please sign in to comment.