我一直在尝试使用MPJExpress发送对象,使用:-
StateP randomState = HeuristicSolverUtility.createRandom(Constants.DIMENSION , Constants.w1);
MPI.COMM_WORLD.Isend(randomState , 0 , 1 , MPI.OBJECT , 3 , Constants.STARTOPERATION);
或者,从这里的答案来看,使用这种形式的
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
{
这个问题没有公认的解决方案:-用MPJ express 发送对象
投票最多的答案对我来说不起作用。我该如何纠正,我做错了什么?
如果需要,这是我的MPJ.I接收功能
StateP startingState = HeuristicSolverUtility.generateGoalState(Constants.DIMENSION, Constants.w1);
Request request = MPI.COMM_WORLD.Irecv(startingState, 0, 1, MPI.OBJECT, 0, Constants.STARTOPERATION);
request.Wait();
试试吧!
Object[] sendArr = new Object[1];
sendArr[0] = (Object) randomState;
MPI.COMM_WORLD.Isend(sendArr , 0 , 1 , MPI.OBJECT , 3 , Constants.STARTOPERATION);