Skip to content

Commit

Permalink
ROBUSTNESS: Now content of PBS_NODEFILE is validated against PBS_NP a…
Browse files Browse the repository at this point in the history
…nd PBS_NUM_NODES * PBS_NUM_PPN. If inconsistent, a warning is generated. [#118]
  • Loading branch information
HenrikBengtsson committed Jan 7, 2017
1 parent adefc61 commit 4ff0ed6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
18 changes: 18 additions & 0 deletions R/availableWorkers.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ availableWorkers <- function(methods=getOption("future.availableCores.methods",
}
data <- read_pbs_nodefile(pathname)
w <- data$node

## Sanity checks
pbs_np <- as.integer(getenv("PBS_NP"))
if (!identical(pbs_np, length(w))) {
warning(sprintf("Identified %d workers from the %s file (%s), which does not match environment variable %s = %d", length(w), sQuote("PBS_NODEFILE"), sQuote(pathname), sQuote("PBS_NP"), pbs_np))
}

pbs_nodes <- as.integer(getenv("PBS_NUM_NODES"))
pbs_ppn <- as.integer(getenv("PBS_NUM_PPN"))
pbs_np <- pbs_nodes * pbs_ppn
if (!identical(pbs_np, length(w))) {
warning(sprintf("Identified %d workers from the %s file (%s), which does not match environment variables %s * %s = %d * %d = %d", length(w), sQuote("PBS_NODEFILE"), sQuote(pathname), sQuote("PBS_NUM_NODES"), sQuote("PBS_NUM_PPN"), pbs_nodes, pbs_ppn, pbs_np))
}

## TO DO: Add validation of 'w' (from PBS_HOSTFILE) toward
## counts in PBS_NP and / or PBS_NUM_NODES * PBS_NUM_PPN.
} else if (method == "SGE") {
pathname <- getenv("PE_HOSTFILE")
if (is.na(pathname)) next
Expand All @@ -98,6 +114,8 @@ availableWorkers <- function(methods=getOption("future.availableCores.methods",
}
data <- read_pe_hostfile(pathname)
w <- expand_nodes(data)

## Sanity checks
nslots <- as.integer(getenv("NSLOTS"))
if (!identical(nslots, length(w))) {
warning(sprintf("Identified %d workers from the %s file (%s), which does not match environment variable %s = %d", length(w), sQuote("PE_HOSTFILE"), sQuote(pathname), sQuote("NSLOTS"), nslots))
Expand Down
5 changes: 4 additions & 1 deletion tests/availableWorkers.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ expand_nodes <- future:::expand_nodes
read_pbs_nodefile <- future:::read_pbs_nodefile
read_pe_hostfile <- future:::read_pe_hostfile

workers0 <- c("n1", "n2", "n3", "n1", "n6", "n3", "n3")
workers0 <- c("n1", "n2", "n3", "n1", "n6", "n3", "n3", "n5")
data0 <- as.data.frame(table(workers0), stringsAsFactors = FALSE)
colnames(data0) <- c("node", "count")
data0 <- data0[order(data0$node, data0$count), ]
Expand All @@ -56,6 +56,9 @@ stopifnot(
)

Sys.setenv(PBS_NODEFILE = pathname)
Sys.setenv(PBS_NP = length(workers),
PBS_NUM_NODES = length(workers) / 2,
PBS_NUM_PPN = 2)
workers <- availableWorkers(methods = "PBS")
print(workers)
stopifnot(length(workers) == length(workers0), all(workers == sort(workers0)))
Expand Down

0 comments on commit 4ff0ed6

Please sign in to comment.