0

I have been trying to use MPJExpress to send a object using :-

StateP randomState = HeuristicSolverUtility.createRandom(Constants.DIMENSION , Constants.w1);

MPI.COMM_WORLD.Isend(randomState , 0 , 1 , MPI.OBJECT , 3 , Constants.STARTOPERATION);

Or using, from this answer here , in this form

StateP[] stateArray = new StateP[1];
stateArray[0] = randomState;
MPI.COMM_WORLD.Isend(stateArray , 0 , 1 , MPI.OBJECT , 3 , Constants.STARTOPERATION);

I get this exception when the above line of code gets executed :-

java.lang.reflect.InvocationTargetException

Caused by: mpi.MPIException: mpi.MPIException: java.lang.ClassCastException: common.model.StateP cannot be cast to [Ljava.lang.Object;
    at mpi.Comm$9.handleCompletion(Comm.java:1678)

StateP class is serializable

public class StateP implements State , Serializable
{

There is no accepted solution to this question here :- Send objects with MPJ express

and the most voted answer doesn't work for me. How can I correct this, what am I doing wrong ?

If needed, this is my MPJ.IReceive function

StateP startingState = HeuristicSolverUtility.generateGoalState(Constants.DIMENSION, Constants.w1);
        Request request = MPI.COMM_WORLD.Irecv(startingState, 0, 1, MPI.OBJECT, 0, Constants.STARTOPERATION);
        request.Wait();
Community
  • 1
  • 1
  • Could you try the second answer to that post? That looks to me like it should fix your problem. – hugh Jul 05 '15 at 08:12

1 Answers1

1

Give it a try!

 Object[] sendArr = new Object[1];
 sendArr[0] = (Object) randomState;
 MPI.COMM_WORLD.Isend(sendArr , 0 , 1 , MPI.OBJECT , 3 , Constants.STARTOPERATION);
Hamza Zafar
  • 1,320
  • 12
  • 17