
org.pcj.internal.message.accumulate.ValueAccumulateResponseMessage Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pcj Show documentation
Show all versions of pcj Show documentation
PCJ is Java library for parallel computing in Java. It is based on the PGAS (Partitioned Global Address Space) paradigm. It allows for easy implementation in Java of any parallel algorithm. PCJ application can be run on laptop, workstation, cluster and HPC system including large supercomputers.
The newest version!
/*
* Copyright (c) 2011-2019, PCJ Library, Marek Nowicki
* All rights reserved.
*
* Licensed under New BSD License (3-clause license).
*
* See the file "LICENSE" for the full license governing this code.
*/
package org.pcj.internal.message.accumulate;
import java.io.IOException;
import java.nio.channels.SocketChannel;
import org.pcj.internal.InternalGroup;
import org.pcj.internal.InternalPCJ;
import org.pcj.internal.NodeData;
import org.pcj.internal.PcjThread;
import org.pcj.internal.message.Message;
import org.pcj.internal.message.MessageType;
import org.pcj.internal.network.MessageDataInputStream;
import org.pcj.internal.network.MessageDataOutputStream;
/**
* @author Marek Nowicki ([email protected])
*/
public class ValueAccumulateResponseMessage extends Message {
private int requestNum;
private int groupId;
private int requesterThreadId;
private Exception exception;
public ValueAccumulateResponseMessage() {
super(MessageType.VALUE_ACCUMULATE_RESPONSE);
}
public ValueAccumulateResponseMessage(int groupId, int requestNum, int requesterThreadId) {
this();
this.groupId = groupId;
this.requestNum = requestNum;
this.requesterThreadId = requesterThreadId;
}
public void setException(Exception exception) {
this.exception = exception;
}
@Override
public void write(MessageDataOutputStream out) throws IOException {
out.writeInt(groupId);
out.writeInt(requestNum);
out.writeInt(requesterThreadId);
out.writeBoolean(exception != null);
if (exception != null) {
out.writeObject(exception);
}
}
@Override
public void onReceive(SocketChannel sender, MessageDataInputStream in) throws IOException {
groupId = in.readInt();
requestNum = in.readInt();
requesterThreadId = in.readInt();
boolean exceptionOccurred = in.readBoolean();
if (exceptionOccurred) {
try {
exception = (Exception) in.readObject();
} catch (Exception ex) {
exception = ex;
}
}
NodeData nodeData = InternalPCJ.getNodeData();
PcjThread pcjThread = nodeData.getPcjThread(groupId, requesterThreadId);
InternalGroup group = pcjThread.getThreadData().getGroupById(groupId);
ValueAccumulateStates states = group.getValueAccumulateStates();
ValueAccumulateStates.State state = states.remove(requestNum);
state.signal(exception);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy