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>:
Hello!
I'm experimenting with using MPI with Fortran rather than C. However, mpiexec does not appear to be working.
Here are my various input files (note: these are VERY simple-minded until I get things running)
Fortran:
subroutine hellosub(size)
include '/usr/local/bin/include/mpif.h'
integer rank,size,ierror,tag,status(MPI_STATUS_SIZE)
call MPI_INIT(ierror)
call MPI_COMM_SIZE(MPI_COMM_WORLD,size,ierror)
call MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierror)
call MPI_FINALIZE(ierror)
end
Compilation statement:
mpif90 -shared -o hellosub.so hellosub.o
(no errors)
R code: (e4.in)
source("rmpi.test.R)
library(Rmpi)
dyn.load("hellousub.so")
rmpi.test(1)
rmpi.test.R
rmpi.test <-function(size) {
dyn.load("hellosub.so")
xplanet <- .Fortran("hellosub",size=as.integer(1))$size
cat("There are ", xplanet," planets in our universe\n")
}
Final run:
mpiexec -np 4 R CMD BATCH e4.in e4.in
===================================================================================
= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
= PID 606 RUNNING AT Es-MacBook-Air.local
= EXIT CODE: 1
= CLEANING UP REMAINING PROCESSES
= YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
===================================================================================
This is run on a MacBook Air, with R Version 3.2.2. The OS on the Mac is Yosemite, Version 10.10.5
The mpif90 compiler is version 5.1.0.
Is it possible/plausible that R doesn't like the Fortran version of the MPI, please?
Thanks for any help!
Sincerely,
Erin
[[alternative HTML version deleted]]
_______________________________________________ R-sig-hpc mailing list R-sig-hpc at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-hpc
Best Regards, -- Eiji NAKAMA <nakama (a) ki.rim.or.jp> "\u4e2d\u9593\u6804\u6cbb" <nakama (a) ki.rim.or.jp>