Something went wrong on our end
-
kra568 authored
[ENH] fixed compilation, utilization of Salomon modules, inclusion of PETSc framework in the parallel version of levenberg-marquardt algorithm, minor fixes of the acsf example and run scripts
kra568 authored[ENH] fixed compilation, utilization of Salomon modules, inclusion of PETSc framework in the parallel version of levenberg-marquardt algorithm, minor fixes of the acsf example and run scripts
mpi_wrapper.h 2.19 KiB
#ifndef INC_4NEURO_MPIWRAPPER_H
#define INC_4NEURO_MPIWRAPPER_H
#include <mpi.h>
/* lib4neuro MPI struct & macros */
namespace lib4neuro{
extern int mpi_rank;
extern int mpi_nranks;
extern int mpi_msg;
extern int mpi_msg_;
extern MPI_Comm mpi_active_comm;
}
#ifdef WITH_PETSC
#include <petscsys.h>
#define MPI_INIT { \
PetscErrorCode ierr; \
ierr = PetscInitialize(&argc,&argv,(char*)0,NULL); \
if (ierr) return ierr; \
MPI_Comm_size( lib4neuro::mpi_active_comm, &lib4neuro::mpi_nranks ); \
MPI_Comm_rank( lib4neuro::mpi_active_comm, &lib4neuro::mpi_rank ); \
}
#define MPI_INIT_NULL { \
PetscErrorCode ierr; \
ierr = PetscInitialize(NULL, NULL,(char*)0,NULL); \
if (ierr) return ierr; \
MPI_Comm_size( lib4neuro::mpi_active_comm, &lib4neuro::mpi_nranks ); \
MPI_Comm_rank( lib4neuro::mpi_active_comm, &lib4neuro::mpi_rank ); \
}
#define MPI_FINISH PetscFinalize( );
#else
#define MPI_INIT { \
MPI_Init(&argc, &argv); \
MPI_Comm_size( lib4neuro::mpi_active_comm, &lib4neuro::mpi_nranks ); \
MPI_Comm_rank( lib4neuro::mpi_active_comm, &lib4neuro::mpi_rank ); \
}
#define MPI_INIT_NULL { \
MPI_Init(nullptr, nullptr); \
MPI_Comm_size( lib4neuro::mpi_active_comm, &lib4neuro::mpi_nranks ); \
MPI_Comm_rank( lib4neuro::mpi_active_comm, &lib4neuro::mpi_rank ); \
}
#define MPI_FINISH MPI_Finalize( );
#endif
#define MPI_INTERRUPT lib4neuro::mpi_msg = 1; MPI_Allreduce(&lib4neuro::mpi_msg, &lib4neuro::mpi_msg_, 1, MPI_INT, MPI_SUM, lib4neuro::mpi_active_comm);
#define MPI_ERROR_CHECK lib4neuro::mpi_msg = 0; MPI_Allreduce(&lib4neuro::mpi_msg, &lib4neuro::mpi_msg_, 1, MPI_INT, MPI_SUM, lib4neuro::mpi_active_comm);; if( lib4neuro::mpi_msg_ > 0 ){throw std::runtime_error(" error " );}
#endif //INC_4NEURO_MPIWRAPPER_H