引起:mpi.MPIException:java.lang.ClassCastException:无法强制转换为[Ljava.lang.Object;

时间:2015-07-05 07:59:12

标签: java debugging mpi mpj-express

我一直在尝试使用MPJExpress发送对象: -

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

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

或使用此答案here,以此形式

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

当执行上面的代码行时,我得到了这个异常: -

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类是可序列化的

public class StateP implements State , Serializable
{

这里没有可接受的解决方案: - Send objects with MPJ express

并且投票最多的答案对我不起作用。 我怎么能纠正这个,我做错了什么?

如果需要,这是我的MPJ.IReceive功能

StateP startingState = HeuristicSolverUtility.generateGoalState(Constants.DIMENSION, Constants.w1);
        Request request = MPI.COMM_WORLD.Irecv(startingState, 0, 1, MPI.OBJECT, 0, Constants.STARTOPERATION);
        request.Wait();

1 个答案:

答案 0 :(得分:0)

试一试!

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