Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

Subject: Re: [OMPI users] [Open MPI] #3351: JAVA scatter error
From: Jeff Squyres (jsquyres_at_[hidden])
Date: 2012-12-17 17:12:19

On Dec 15, 2012, at 10:46 AM, Siegmar Gross wrote:

>> 1. The datatypes passed to Scatter are not valid MPI datatypes
>> (MPI.OBJECT). You need to construct a datatype that is specific to the
>> !MyData class, just like you would in C/C++. I think that this is the
>> first error that you are seeing (i.e., that OMPI is trying to treat
>> MPI.OBJECT as an MPI Datatype object, and failing (and therefore throwing
>> an !ClassCastException exception).
> Perhaps you are right and my small example program ist not a valid MPI
> program. The problem is that I couldn't find any good documentation or
> example programs how to write a program which uses a structured data
> type.

In Java, that's probably true. Remember: there are no official MPI Java bindings. What is included in Open MPI is a research project from several years ago. We picked what appeared to be the best one, freshened it up a little, updated its build system to incorporate into ours, verified its basic functionality, and went with that.

In C, there should be plenty of google-able examples about how to use Scatter (and friends). You might want to have a look at a few of those to get an idea how to use MPI_Scatter in general, and then apply that knowledge to a Java program.

Make sense?

> Therefore I sticked to the mpiJava specification which states
> for derived datatypes in chapter 3.12 that the effect for MPI_Type_struct
> can be achieved by using MPI.OBJECT as the buffer type and relying on
> Java object serialization. "dataItem" is a serializable Java object and
> I used MPI.OBJECT as buffer type. How can I create a valid MPI datatype
> MPI.OBJECT so that I get a working example program?

/me reads some Java implementation code...

It looks like they allow passing MPI.OBJECT as the datatype argument; sorry, I guess I was wrong about that.

> MPI.COMM_WORLD.Scatter (dataItem, 0, 1, MPI.OBJECT,
> objBuffer, 0, 1, MPI.OBJECT, 0);

What I think you're running into here is that you're still using Scatter wrong, per my other point, below:

>> 1. It looks like you're trying to Scatter a single object to N peers.
>> That's invalid MPI -- you need to scatter (N*M) objects to N peers, where
>> M is a positive integer value (e.g., 1 or 2). Are you trying to
>> broadcast?
> It is the very first version of the program where I scatter one object
> to the process itself (at this point it is not the normal application
> area for scatter, but should nevertheless work). I didn't continue due
> to the error. I get the same error when I broadcast my data item.
> tyr java 116 mpiexec -np 1 java -cp $DIRPREFIX_LOCAL/mpi_classfiles \
> ObjectScatterMain
> Exception in thread "main" java.lang.ClassCastException: MyData cannot
> be cast to [Ljava.lang.Object;
> at mpi.Intracomm.copyBuffer(
> at mpi.Intracomm.Scatter(
> at ObjectScatterMain.main(

I don't know Java, but it looks like it's complaining about the type of dataItem, not the type of MPI.OBJECT. It says it can't cast dataItem to a Ljava.lang.Object -- which appears to be the type of the first argument to Scatter.

Do you need to have MyData inherit from the Java base Object type, or some such?

> "Broadcast" works if I have only a root process and it fails when I have
> one more process.

If I change MPI.COMM_WORLD.Scatter(...) to

        MPI.COMM_WORLD.Bcast(dataItem, 0, 1, MPI.OBJECT, 0);

I get the same casting error.

I'm sorry; I really don't know Java, and don't know how to fix this offhand.

Jeff Squyres
For corporate legal information go to: