From 7a516781d48dfe81703bce680a12983d4f100e9e Mon Sep 17 00:00:00 2001 From: DylanKierans Date: Mon, 18 Mar 2024 17:30:03 +0100 Subject: [PATCH] Revert "Removing mpi from testing" This reverts commit 1478129e42878317517ad48b13a3781896feb631. --- .github/workflows/R-CMD-check.yaml | 13 ++++++ R/RcppExports.R | 25 ++++++++++ man/get_env.Rd | 14 ++++++ man/get_mpi_rank.Rd | 11 +++++ man/get_mpi_size.Rd | 11 +++++ man/mpi_finalize.Rd | 11 +++++ man/mpi_init.Rd | 11 +++++ man/mpi_is_init.Rd | 11 +++++ src/Makevars | 10 +++- src/RcppExports.cpp | 55 ++++++++++++++++++++++ src/rTrace.cpp | 73 ++++++++++++++++++++++++++++++ 11 files changed, 243 insertions(+), 2 deletions(-) create mode 100644 man/get_env.Rd create mode 100644 man/get_mpi_rank.Rd create mode 100644 man/get_mpi_size.Rd create mode 100644 man/mpi_finalize.Rd create mode 100644 man/mpi_init.Rd create mode 100644 man/mpi_is_init.Rd diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 53bd238..156006c 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -58,6 +58,19 @@ jobs: run: | brew install otf2 + # MANUAL OPENMPI INSTALL + - name: Install openmpi (linux) + if: runner.os == 'linux' + run: | + sudo apt-get install libopenmpi-dev + export MPI_ROOT=$(which mpicc | xargs dirname | xargs dirname) + + - name: Install openmpi (mac) + if: runner.os == 'macOS' + run: | + brew install open-mpi + export MPI_ROOT=$(which mpicc | xargs dirname | xargs dirname) + - uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: any::rcmdcheck diff --git a/R/RcppExports.R b/R/RcppExports.R index 888b8b4..5cacb01 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -113,3 +113,28 @@ get_ppid <- function() { .Call('_rTrace_get_ppid', PACKAGE = 'rTrace') } +#' mpi_init +mpi_init <- function() { + .Call('_rTrace_mpi_init', PACKAGE = 'rTrace') +} + +#' mpi_finalize +mpi_finalize <- function() { + .Call('_rTrace_mpi_finalize', PACKAGE = 'rTrace') +} + +#' mpi_is_init +mpi_is_init <- function() { + .Call('_rTrace_mpi_is_init', PACKAGE = 'rTrace') +} + +#' get_mpi_rank +get_mpi_rank <- function() { + .Call('_rTrace_get_mpi_rank', PACKAGE = 'rTrace') +} + +#' get_mpi_size +get_mpi_size <- function() { + .Call('_rTrace_get_mpi_size', PACKAGE = 'rTrace') +} + diff --git a/man/get_env.Rd b/man/get_env.Rd new file mode 100644 index 0000000..f9bc4f8 --- /dev/null +++ b/man/get_env.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/r_utils.R +\name{get_env} +\alias{get_env} +\title{get_env} +\usage{ +get_env() +} +\value{ +Environment +} +\description{ +Get environment object for this package rTrace +} diff --git a/man/get_mpi_rank.Rd b/man/get_mpi_rank.Rd new file mode 100644 index 0000000..0fef67e --- /dev/null +++ b/man/get_mpi_rank.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{get_mpi_rank} +\alias{get_mpi_rank} +\title{get_mpi_rank} +\usage{ +get_mpi_rank() +} +\description{ +get_mpi_rank +} diff --git a/man/get_mpi_size.Rd b/man/get_mpi_size.Rd new file mode 100644 index 0000000..4065066 --- /dev/null +++ b/man/get_mpi_size.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{get_mpi_size} +\alias{get_mpi_size} +\title{get_mpi_size} +\usage{ +get_mpi_size() +} +\description{ +get_mpi_size +} diff --git a/man/mpi_finalize.Rd b/man/mpi_finalize.Rd new file mode 100644 index 0000000..9f73f23 --- /dev/null +++ b/man/mpi_finalize.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{mpi_finalize} +\alias{mpi_finalize} +\title{mpi_finalize} +\usage{ +mpi_finalize() +} +\description{ +mpi_finalize +} diff --git a/man/mpi_init.Rd b/man/mpi_init.Rd new file mode 100644 index 0000000..e9d1b0e --- /dev/null +++ b/man/mpi_init.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{mpi_init} +\alias{mpi_init} +\title{mpi_init} +\usage{ +mpi_init() +} +\description{ +mpi_init +} diff --git a/man/mpi_is_init.Rd b/man/mpi_is_init.Rd new file mode 100644 index 0000000..e678430 --- /dev/null +++ b/man/mpi_is_init.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{mpi_is_init} +\alias{mpi_is_init} +\title{mpi_is_init} +\usage{ +mpi_is_init() +} +\description{ +mpi_is_init +} diff --git a/src/Makevars b/src/Makevars index 303a8f2..6ce79ea 100644 --- a/src/Makevars +++ b/src/Makevars @@ -2,5 +2,11 @@ OTF2_PKG_CPPFLAGS=-I${OTF2_ROOT}/include -I. OTF2_PKG_LIBS=-L${OTF2_ROOT}/lib -L. -lotf2 -PKG_CPPFLAGS=${OTF2_PKG_CPPFLAGS} -PKG_LIBS=${OTF2_PKG_LIBS} +# mpi +#MPI_PKG_CPPFLAGS=$(mpicc -showme:compile) +#MPI_PKG_LIBS=$(mpicc -showme:link) +MPI_PKG_CPPFLAGS=-I${MPI_ROOT}/include +MPI_PKG_LIBS=-L${MPI_ROOT}/lib -lmpi + +PKG_CPPFLAGS=${OTF2_PKG_CPPFLAGS} ${MPI_PKG_CPPFLAGS} +PKG_LIBS=${OTF2_PKG_LIBS} ${MPI_PKG_LIBS} diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 504119e..d25c27a 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -191,6 +191,56 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// mpi_init +RcppExport int mpi_init(); +RcppExport SEXP _rTrace_mpi_init() { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + rcpp_result_gen = Rcpp::wrap(mpi_init()); + return rcpp_result_gen; +END_RCPP +} +// mpi_finalize +RcppExport SEXP mpi_finalize(); +RcppExport SEXP _rTrace_mpi_finalize() { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + rcpp_result_gen = Rcpp::wrap(mpi_finalize()); + return rcpp_result_gen; +END_RCPP +} +// mpi_is_init +RcppExport int mpi_is_init(); +RcppExport SEXP _rTrace_mpi_is_init() { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + rcpp_result_gen = Rcpp::wrap(mpi_is_init()); + return rcpp_result_gen; +END_RCPP +} +// get_mpi_rank +RcppExport int get_mpi_rank(); +RcppExport SEXP _rTrace_get_mpi_rank() { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + rcpp_result_gen = Rcpp::wrap(get_mpi_rank()); + return rcpp_result_gen; +END_RCPP +} +// get_mpi_size +RcppExport int get_mpi_size(); +RcppExport SEXP _rTrace_get_mpi_size() { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + rcpp_result_gen = Rcpp::wrap(get_mpi_size()); + return rcpp_result_gen; +END_RCPP +} static const R_CallMethodDef CallEntries[] = { {"_rTrace_init_Archive", (DL_FUNC) &_rTrace_init_Archive, 2}, @@ -210,6 +260,11 @@ static const R_CallMethodDef CallEntries[] = { {"_rTrace_get_pid", (DL_FUNC) &_rTrace_get_pid, 0}, {"_rTrace_get_tid", (DL_FUNC) &_rTrace_get_tid, 0}, {"_rTrace_get_ppid", (DL_FUNC) &_rTrace_get_ppid, 0}, + {"_rTrace_mpi_init", (DL_FUNC) &_rTrace_mpi_init, 0}, + {"_rTrace_mpi_finalize", (DL_FUNC) &_rTrace_mpi_finalize, 0}, + {"_rTrace_mpi_is_init", (DL_FUNC) &_rTrace_mpi_is_init, 0}, + {"_rTrace_get_mpi_rank", (DL_FUNC) &_rTrace_get_mpi_rank, 0}, + {"_rTrace_get_mpi_size", (DL_FUNC) &_rTrace_get_mpi_size, 0}, {NULL, NULL, 0} }; diff --git a/src/rTrace.cpp b/src/rTrace.cpp index 4795cf8..1be957a 100644 --- a/src/rTrace.cpp +++ b/src/rTrace.cpp @@ -14,6 +14,10 @@ #include #include +// if (MPI) +#include + + //#define DEBUG /* Uncomment to enable verbose debug info */ //#define DUMMY_TIMESTEPS /* Uncomment for 1s timestep for each subsequent event call */ @@ -382,3 +386,72 @@ RcppExport int get_tid() { RcppExport int get_ppid() { return((int)getppid()); } + +//' mpi_init +// [[Rcpp::export]] +RcppExport int mpi_init() { + int flag; + int fake_argc = 0; + char **fake_argv = NULL; +//char **fake_argv = malloc(1*sizeof(*fake_argv)); + MPI_Init(&fake_argc, &fake_argv); + free(fake_argv); + + MPI_Initialized(&flag); + if (flag) { + Rcout << "MPI is initialized.\n"; + return(0); + } + Rcout << "MPI UNABLE to initialize.\n"; + return (-1); +} + +//' mpi_finalize +// [[Rcpp::export]] +RcppExport SEXP mpi_finalize() { + MPI_Finalize(); + return(R_NilValue); +} + +//' mpi_is_init +// [[Rcpp::export]] +RcppExport int mpi_is_init() { + int init_flag; + MPI_Initialized(&init_flag); + if (init_flag) { + Rcout << "MPI is initialized.\n"; + return(0); + } + Rcout << "MPI is NOT initialized\n"; + return (-1); +} + +//' get_mpi_rank +// [[Rcpp::export]] +RcppExport int get_mpi_rank() { + int rank, init_flag; + MPI_Initialized(&init_flag); + if (init_flag) { + Rcout << "MPI is initialized.\n"; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + return(rank); + } + Rcout << "MPI is NOT initialized\n"; + return (-1); +} + +//' get_mpi_size +// [[Rcpp::export]] +RcppExport int get_mpi_size() { + int size, init_flag; + MPI_Initialized(&init_flag); + if (init_flag) { + Rcout << "MPI is initialized.\n"; + MPI_Comm_size(MPI_COMM_WORLD, &size); + return(size); + } + Rcout << "MPI is NOT initialized\n"; + return (-1); +} + +