use of edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException in project twister2 by DSC-SPIDAL.
the class JepInstance method initialValue.
@Override
protected Jep initialValue() {
JepConfig jepConfig = new JepConfig();
jepConfig.setRedirectOutputStreams(true);
// );
try {
TSharedInterpreter jep = new TSharedInterpreter(jepConfig);
jep.eval("import cloudpickle as cp");
jep.eval("import base64");
jep.eval("from abc import ABC, abstractmethod");
jep.eval("import numpy as np");
jep.eval("import twister2.utils as utils");
return jep;
} catch (JepException jex) {
throw new Twister2RuntimeException("Couldn't create a JEP instance", jex);
}
}
use of edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException in project twister2 by DSC-SPIDAL.
the class SimpleAllToAll method insert.
public boolean insert(ByteBuffer buf, int length, int[] header, int headerLength, int target) {
if (finishFlag) {
throw new Twister2RuntimeException("Cannot insert after finishing");
}
if (headerLength > MPIChannel.TWISTERX_CHANNEL_USER_HEADER) {
throw new Twister2RuntimeException("Cannot have a header length greater than " + MPIChannel.TWISTERX_CHANNEL_USER_HEADER);
}
AllToAllSends s = sends.get(target);
TRequest request = new TRequest(target, buf, length, header, headerLength);
s.requestQueue.offer(request);
return true;
}
use of edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException in project twister2 by DSC-SPIDAL.
the class SimpleAllToAll method isComplete.
public boolean isComplete() {
boolean allQueuesEmpty = true;
for (AllToAllSends s : sends.values()) {
while (!s.requestQueue.isEmpty()) {
if (s.sendStatus == AllToAllSendStatus.FINISH_SENT || s.sendStatus == AllToAllSendStatus.FINISHED) {
String msg = "We cannot have items to send after finish sent";
LOG.log(Level.SEVERE, msg);
throw new Twister2RuntimeException(msg);
}
TRequest request = s.requestQueue.peek();
if (1 == channel.send(request)) {
s.requestQueue.poll();
s.pendingQueue.offer(request);
}
}
if (s.pendingQueue.isEmpty()) {
if (finishFlag) {
if (s.sendStatus == AllToAllSendStatus.SENDING) {
TRequest request = new TRequest(s.target);
if (1 == channel.sendFin(request)) {
s.sendStatus = AllToAllSendStatus.FINISH_SENT;
}
}
}
} else {
allQueuesEmpty = false;
}
}
channel.progressReceives();
channel.progressSends();
return allQueuesEmpty && finishedTargets.size() == targets.size() && finishedSources.size() == sources.size();
}
use of edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException in project twister2 by DSC-SPIDAL.
the class ReduceOperationFunction method applyOp.
/**
* Applying the operation on data
*/
public Object applyOp(Object data1, Object data2, AbstractOp op) {
if (this.messageType == MessageTypes.INTEGER_ARRAY) {
if (data1 instanceof int[] && data2 instanceof int[]) {
int[] i1 = (int[]) data1;
int[] i2 = (int[]) data2;
validateArrayLength(i1.length, i2.length);
int[] res = new int[i1.length];
for (int i = 0; i < i1.length; i++) {
res[i] = op.doInt(i1[i], i2[i]);
}
return res;
} else {
throw new RuntimeException(String.format("Message should be a %s array, got %s and %s", "int", data1.getClass(), data2.getClass()));
}
} else if (this.messageType == MessageTypes.INTEGER) {
return op.doInt((int) data1, (int) data2);
} else if (this.messageType == MessageTypes.DOUBLE_ARRAY) {
if (data1 instanceof double[] && data2 instanceof double[]) {
double[] i1 = (double[]) data1;
double[] i2 = (double[]) data2;
validateArrayLength(i1.length, i2.length);
double[] res = new double[i1.length];
for (int i = 0; i < i1.length; i++) {
res[i] = op.doDouble(i1[i], i2[i]);
}
return res;
} else {
throw new RuntimeException(String.format("Message should be a %s array, got %s and %s", "double", data1.getClass(), data2.getClass()));
}
} else if (this.messageType == MessageTypes.DOUBLE) {
return op.doDouble((double) data1, (double) data2);
} else if (this.messageType == MessageTypes.SHORT_ARRAY) {
if (data1 instanceof short[] && data2 instanceof short[]) {
short[] i1 = (short[]) data1;
short[] i2 = (short[]) data2;
validateArrayLength(i1.length, i2.length);
short[] res = new short[i1.length];
for (int i = 0; i < i1.length; i++) {
res[i] = op.doShort(i1[i], i2[i]);
}
return res;
} else {
throw new RuntimeException(String.format("Message should be a %s array, got %s and %s", "short", data1.getClass(), data2.getClass()));
}
} else if (this.messageType == MessageTypes.SHORT) {
return op.doShort((short) data1, (short) data2);
} else if (this.messageType == MessageTypes.BYTE_ARRAY) {
if (data1 instanceof byte[] && data2 instanceof byte[]) {
byte[] i1 = (byte[]) data1;
byte[] i2 = (byte[]) data2;
validateArrayLength(i1.length, i2.length);
byte[] res = new byte[i1.length];
for (int i = 0; i < i1.length; i++) {
res[i] = op.doByte(i1[i], i2[i]);
}
return res;
} else {
throw new RuntimeException(String.format("Message should be a %s array, got %s and %s", "byte", data1.getClass(), data2.getClass()));
}
} else if (this.messageType == MessageTypes.BYTE) {
return op.doByte((byte) data1, (byte) data2);
} else if (this.messageType == MessageTypes.LONG_ARRAY) {
if (data1 instanceof long[] && data2 instanceof long[]) {
long[] i1 = (long[]) data1;
long[] i2 = (long[]) data2;
validateArrayLength(i1.length, i2.length);
long[] res = new long[i1.length];
for (int i = 0; i < i1.length; i++) {
res[i] = op.doLong(i1[i], i2[i]);
}
return res;
} else {
throw new RuntimeException(String.format("Message should be a %s array, got %s and %s", "long", data1.getClass(), data2.getClass()));
}
} else if (this.messageType == MessageTypes.LONG) {
return op.doLong((long) data1, (long) data2);
} else {
throw new Twister2RuntimeException("Message type is not supported for this operation");
}
}
use of edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException in project twister2 by DSC-SPIDAL.
the class BufferedCollectionPartition method getConsumer.
@Override
public DataPartitionConsumer<T> getConsumer() {
final Iterator<T> inMemoryIterator = this.dataList.iterator();
final Iterator<Path> fileIterator = this.filesList.iterator();
final Iterator<byte[]> buffersIterator = this.buffers.iterator();
return new DataPartitionConsumer<T>() {
private Queue<byte[]> bufferFromDisk = new LinkedList<>();
@Override
public boolean hasNext() {
return inMemoryIterator.hasNext() || fileIterator.hasNext() || buffersIterator.hasNext() || !bufferFromDisk.isEmpty();
}
@Override
public T next() {
if (!this.bufferFromDisk.isEmpty()) {
return (T) dataType.getDataPacker().unpackFromByteArray(this.bufferFromDisk.poll());
} else if (inMemoryIterator.hasNext()) {
return inMemoryIterator.next();
} else if (fileIterator.hasNext()) {
Path nextFile = fileIterator.next();
try {
DataInputStream reader = new DataInputStream(fileSystem.open(nextFile));
long noOfFrames = reader.readLong();
for (long i = 0; i < noOfFrames; i++) {
int size = reader.readInt();
byte[] data = new byte[size];
int readSoFar = 0;
while (readSoFar < size) {
int readSize = reader.read(data, readSoFar, data.length - readSoFar);
if (readSize == -1) {
throw new Twister2RuntimeException("Reached the EOF unexpectedly");
}
readSoFar += readSize;
}
this.bufferFromDisk.add(data);
}
return next();
} catch (IOException e) {
throw new Twister2RuntimeException("Failed to read value from the temp file : " + nextFile.toString(), e);
}
} else if (buffersIterator.hasNext()) {
return (T) dataType.getDataPacker().unpackFromByteArray(buffersIterator.next());
}
throw new Twister2RuntimeException("No more frames available in this partition");
}
};
}
Aggregations