Skip to content
Prev 1979 / 2152 Next

Running Rmpi with a Fortran program

hi,
`library(Rmpi)' does MPI_Init inside.
your program, it is a MPI_Init call again in fortran subrutine.
since Rmpi has an array of the communicator of c inside, in the case
of cooperation with external programs, you will need the exchange of
communicator.
please omit call MPI_Init and MPI_Finalize.

c.f.
$ cat hellosub1.f
      subroutine hellosub(comm,rank,size)
      include 'mpif.h'
      integer comm,rank,size,ierror,tag,status(MPI_STATUS_SIZE)
C     call MPI_INIT(ierror)
      call MPI_COMM_SIZE(comm,size,ierror)
      call MPI_COMM_RANK(comm,rank,ierror)
C     call MPI_FINALIZE(ierror)
      end

$ mpif77 -fPIC -shared -o hellosub1.so  hellosub1.f
$ cat rmpi.test1.R
rmpitest <-function(comm) {
    dyn.load("hellosub1.so")
    xplanet <- .Fortran("hellosub",comm=as.integer(comm),rank=as.integer(0),size=as.integer(0))
    cat("There are ", xplanet$rank, xplanet$size," planets in our universe\n")
    dyn.unload("hellosub1.so")
    xplanet$rank
}
library("Rmpi")
rmpitest(mpi.comm.c2f(0)) # number 0 is MPI_COMM_WORLD in Rmpi

$ mpiexec  -np 4 Rscript rmpi.test1.R

If other languages, it would be even more should you use MPI_Comm_f2c...



2015-10-04 0:41 GMT+09:00 Hodgess, Erin <HodgessE at uhd.edu>: