Project

General

Profile

Download (1008 Bytes) Statistics
| Branch: | Revision:
1
# Echo out library paths
2
.libPaths()
3

    
4
# Load the R MPI package if it is not already loaded
5
if (!is.loaded("mpi_initialize")) {
6
  library("Rmpi")
7
}
8

    
9
# Echo out libraries loaded
10
library()
11

    
12
# Echo out what is loaded
13
search()
14

    
15
# Spawn as many slaves as possible
16
mpi.spawn.Rslaves()
17

    
18
# In case R exits unexpectedly, have it automatically clean up
19
# resources taken up by Rmpi (slaves, memory, etc...)
20
.Last <- function(){
21
  if (is.loaded("mpi_initialize")){
22
            if (mpi.comm.size(1) > 0){
23
                              print("Please use mpi.close.Rslaves() to close slaves.")
24
                                              mpi.close.Rslaves()
25
                            }
26
                    print("Please use mpi.quit() to quit R")
27
                    .Call("mpi_finalize")
28
          }
29
}
30

    
31
# Tell all slaves to return a message identifying themselves
32
mpi.remote.exec(paste("I am",mpi.comm.rank(),"of",mpi.comm.size()))
33

    
34
# Tell all slaves to close down, and exit the program
35
mpi.close.Rslaves()
36
mpi.quit()
(4-4/34)