I'm interested in connecting new Java programs with legacy programs
written in C and Fortran using MPI (so that they are machine independent
and parallel). To try this out at first, I was hoping to simply Send
arrays of basic datatypes (integer, floats, etc.) from a Java program to
a simple C or Fortran program. So, I put together a simple example, but
am unable to Send or Receive anything (the program just freezes... I'm
guessing it freezes at the MPI_Send and MPI_Recv calls). What am I doing
wrong (see code below)?
*Java program - interopj.java (sending program): *
import mpi.*;
public class interopj
{
public static void main(String args[])
{
try
{
MPI.Init(args);
int rank = MPI.COMM_WORLD.Rank();
int size = MPI.COMM_WORLD.Size();
int offset = 0, cnt = 1;
int buf[] = new int[cnt];
for (int i = 1; i < size; i++)
{
buf[0] = i;
System.out.println("Sending " + i);
MPI.COMM_WORLD.Send(buf, offset, cnt, MPI.INT, i, 0);
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
MPI.Finalize();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
}
*C program - interop.c (receiving program): *
#include "mpi.h"
int main(int argc, char *argv[])
{
int rank, size;
int i, bsize;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
bsize = 1;
int buf[bsize];
printf("Waiting for an integer");
MPI_Recv(&buf, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
printf("Received %d", buf[0]);
MPI_Finalize();
return 0;
}
*Makefile: *
CC = mpicc
JCC = mpijavac
LIB = /usr/local/lib
all: interop interopj
interop: interop.c
$(CC) -o interop interop.c
interopj: interopj.java
$(JCC) -cp $(LIB)/mpi.jar interopj.java
*Shell file to run a test: *
echo Building
make -B
echo Running
mpirun -np 1 java interopj : -np 2 interop
Thanks for your help in advance,
André