Skip to content

Commit a1fa9bc

Browse files
authored
Merge pull request #84 from snoweye/master
0.4-3 on CRAN
2 parents 0e9b660 + cb70c9e commit a1fa9bc

File tree

7 files changed

+56
-18
lines changed

7 files changed

+56
-18
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2020-01-26: Ver. 0.4-3
2+
* Change "execmpi()" to finalize current mpi first.
3+
4+
2019-12-01: Ver. 0.4-2
5+
* Fix multiple definition warnings due to "-fno-common" as default in gcc-10.
6+
17
2019-11-21: Ver. 0.4-1
28
* Remove "00LOCK-pbdMPI/00new/" from Makeconf generated by Makevars.win for
39
64bit MS-MPI library only.

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: pbdMPI
2-
Version: 0.4-1
3-
Date: 2019-11-21
2+
Version: 0.4-3
3+
Date: 2020-01-24
44
Title: Programming with Big Data -- Interface to MPI
55
Authors@R: c(person("Wei-Chen", "Chen", role = c("aut", "cre"), email =
66
"wccsnow@gmail.com"),

R/util_execmpi.r

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
### Utility
22

33
execmpi <- function(spmd.code = NULL, spmd.file = NULL,
4-
mpicmd = NULL, nranks = 2L, verbose = TRUE){
4+
mpicmd = NULL, nranks = 1L, rscmd = NULL, verbose = TRUE,
5+
disable.current.mpi = TRUE){
56
### Check # of ranks.
67
nranks <- as.integer(nranks)
78
if(nranks <= 0){
@@ -21,7 +22,7 @@ execmpi <- function(spmd.code = NULL, spmd.file = NULL,
2122

2223
### Dump spmd.code to a temp file, execute
2324
spmd.file <- tempfile()
24-
on.exit(unlink(spmd.file))
25+
# on.exit(unlink(spmd.file))
2526
conn <- file(spmd.file, open = "wt")
2627
writeLines(spmd.code, conn)
2728
close(conn)
@@ -72,11 +73,13 @@ execmpi <- function(spmd.code = NULL, spmd.file = NULL,
7273
}
7374

7475
### Find Rscript.
75-
if(Sys.info()[['sysname']] == "Windows"){
76-
rscmd <- paste(Sys.getenv("R_HOME"), "/bin", Sys.getenv("R_ARCH_BIN"),
77-
"/Rscript", sep = "")
78-
} else{
79-
rscmd <- paste(Sys.getenv("R_HOME"), "/bin/Rscript", sep = "")
76+
if(is.null(rscmd)){
77+
if(Sys.info()[['sysname']] == "Windows"){
78+
rscmd <- paste(Sys.getenv("R_HOME"), "/bin", Sys.getenv("R_ARCH_BIN"),
79+
"/Rscript", sep = "")
80+
} else{
81+
rscmd <- paste(Sys.getenv("R_HOME"), "/bin/Rscript", sep = "")
82+
}
8083
}
8184

8285
### Make a cmd.
@@ -88,8 +91,9 @@ execmpi <- function(spmd.code = NULL, spmd.file = NULL,
8891
} else{
8992
log.file <- tempfile()
9093
on.exit(unlink(log.file), add = TRUE)
91-
cmd <- paste(mpicmd, "-np", nranks, rscmd, spmd.file,
92-
">", log.file, "2>&1 & echo \"PID=$!\" &", sep = " ")
94+
cmd <- paste(mpicmd, " -np ", nranks, " ",
95+
rscmd, " -e \"source('", spmd.file, "')\" ",
96+
"> ", log.file, " 2>&1 & echo \"PID=$!\" &", sep = "")
9397
}
9498
if(verbose){
9599
cat(">>> MPI command:\n", cmd, "\n", sep = "")
@@ -100,6 +104,10 @@ execmpi <- function(spmd.code = NULL, spmd.file = NULL,
100104
ret <- system(cmd, intern = TRUE, ignore.stdout = FALSE,
101105
ignore.stderr = FALSE, wait = TRUE)
102106
} else{
107+
if((!is.finalized()) && disable.current.mpi){
108+
finalize(mpi.finalize = TRUE)
109+
}
110+
103111
tmp <- system(cmd, intern = TRUE, ignore.stdout = FALSE,
104112
ignore.stderr = FALSE, wait = FALSE)
105113
if(verbose){

man/uu_execmpi.Rd

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,24 @@
55
\description{
66
This function basically saves code in a spmd.file and executes
77
MPI via R's system call e.g.
8-
\code{system("mpiexec -np 2 Rscript spmd.file")}.
8+
\code{system("mpiexec -np 1 Rscript spmd.file")}.
99
}
1010
\usage{
1111
execmpi(spmd.code = NULL, spmd.file = NULL,
12-
mpicmd = NULL, nranks = 2L, verbose = TRUE)
12+
mpicmd = NULL, nranks = 1L, rscmd = NULL, verbose = TRUE,
13+
disable.current.mpi = TRUE)
1314
runmpi(spmd.code = NULL, spmd.file = NULL,
14-
mpicmd = NULL, nranks = 2L, verbose = TRUE)
15+
mpicmd = NULL, nranks = 1L, rscmd = NULL, verbose = TRUE,
16+
disable.current.mpi = TRUE)
1517
}
1618
\arguments{
1719
\item{spmd.code}{SPMD code to be run via mpicmd and \code{Rscript}.}
1820
\item{spmd.file}{a file contains SPMD code to be run via mpicmd and \code{Rscript}.}
1921
\item{mpicmd}{MPI executable command. If \code{NULL}, system default will be searched.}
2022
\item{nranks}{number of processes to run the SPMD code envoked by mpicmd.}
23+
\item{rscmd}{\code{Rscript} executable command. If \code{NULL}, system default will be searched.}
2124
\item{verbose}{print SPMD code outputs and MPI messages.}
25+
\item{disable.current.mpi}{force to finalize the current MPI comm if any, for unix-alike system only.}
2226
}
2327
\details{
2428
When the \code{spmd.code} is \code{NULL}: The code should be already
@@ -36,14 +40,14 @@ runmpi(spmd.code = NULL, spmd.file = NULL,
3640
used to dump \code{spmd.code}.
3741
3842
For Unix-alike systems, the command
39-
\code{cmd <- paste(mpicmd, "-np", nranks, "Rscript", spmd.file, ">", log.file, " 2>&1 & echo \"PID=$!\" &")}
43+
\code{cmd <- paste(mpicmd, "-np", nranks, rscmd, spmd.file, ">", log.file, " 2>&1 & echo \"PID=$!\" &")}
4044
is executed via \code{system(cmd, intern = TRUE, wait = FALSE, ignore.stdout = TRUE, ignore.stderr = TRUE)}. The \code{log.file} is a temporary file to
4145
save the outputs from the \code{spmd.code}. The results saved to the
4246
\code{log.file} will be read back in and \code{cat} and \code{return}
4347
to R.
4448
4549
For Windows, the \code{cmd} will be
46-
\code{paste(mpicmd, "-np", nranks, "Rscript", spmd.file)}
50+
\code{paste(mpicmd, "-np", nranks, rscmd, spmd.file)}
4751
and is executed via
4852
\code{system(cmd, intern = TRUE, wait = FALSE, ignore.stdout = TRUE, ignore.stderr = TRUE)}.
4953
}
@@ -52,6 +56,23 @@ runmpi(spmd.code = NULL, spmd.file = NULL,
5256
in Linux-alike systems. For Windows, the MPI job is always wait until
5357
it is complete.
5458
}
59+
\note{
60+
For Unix-alike systems,
61+
in new R and MPI, the \code{pbdMPI::execmpi(...)} may
62+
carry the current MPI \code{comm} into \code{system(cmd, ...)} calls.
63+
Because the \code{comm} has been established/loaded by the
64+
\code{init()} call because of \code{::},
65+
the \code{mpiexec} inside the \code{system(cmd, ...)} calls
66+
will be confused with the exist \code{comm}.
67+
68+
Consider that \code{pbdMPI::execmpi(...)} is typically called in
69+
interactive mode (or actually only done for CRAN check in most case),
70+
an argument \code{disable.current.mpi = TRUE} is added/needed to finalize
71+
the existing \code{comm} first before \code{system(cmd, ...)} be executed.
72+
73+
This function is NOT recommended for running SPMD programs.
74+
The recommended way is to run under shell command.
75+
}
5576
\references{
5677
Programming with Big Data in R Website:
5778
\url{http://r-pbd.org/}

src/pkg_constant.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static char VARIABLE_IS_NOT_USED *LOAD_LOCATION[N_LOAD_LOCATION] =
2020
{"UNSET", "Rmpi", "pbdMPI", "VisIt", "pncdf4"};
2121

2222
#define __LOAD_LOCATION__ PBDMPI
23-
int WHO_LOAD_FIRST;
23+
extern int WHO_LOAD_FIRST;
2424
// Whom need to take care free memory.
2525

2626
#define MPI_APTS_R_NAME ".__MPI_APTS__"

src/pkg_global.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct _rmpi_array_pointers{
3939
int *STATUS_MAXSIZE;
4040
int *REQUEST_MAXSIZE;
4141
};
42-
rmpi_array_pointers MPI_APTS, *MPI_APTS_ptr;
42+
extern rmpi_array_pointers MPI_APTS, *MPI_APTS_ptr;
4343

4444
/* In "pkg_tools.c". */
4545
SEXP arrange_MPI_APTS();

src/pkg_tools.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include "pkg_global.h"
99
#include <stdint.h>
1010

11+
rmpi_array_pointers MPI_APTS, *MPI_APTS_ptr = NULL;
12+
int WHO_LOAD_FIRST;
13+
1114
SEXP arrange_MPI_APTS(){
1215
SEXP R_apts;
1316

0 commit comments

Comments
 (0)