use of org.openucx.jucx.ucp.UcpListener in project twister2 by DSC-SPIDAL.
the class TWSUCXChannel method createUcpListener.
/**
* create a UcpListener on a random port between 15k and 65k
* if a chosen port is taken, try other random ports
* @param ucpWorker
* @param wIP
* @return
*/
private static UcpListener createUcpListener(UcpWorker ucpWorker, InetAddress wIP) {
Random rg = new Random();
UcpListenerParams ucpListenerParams = new UcpListenerParams();
int tryCount = 0;
int maxTryCount = 10;
while (tryCount++ < maxTryCount) {
// generate random port numbers in the range of 15k to 65k
int port = rg.nextInt(40000) + 15000;
ucpListenerParams.setSockAddr(new InetSocketAddress(wIP.getHostAddress(), port));
try {
UcpListener ucpListener = ucpWorker.newListener(ucpListenerParams);
return ucpListener;
} catch (UcxException ucxException) {
if (tryCount == maxTryCount) {
throw new Twister2RuntimeException(ucxException);
}
}
}
return null;
}
use of org.openucx.jucx.ucp.UcpListener in project twister2 by DSC-SPIDAL.
the class TWSUCXChannel method createUXCWorker.
private void createUXCWorker(IWorkerController iWorkerController) {
UcpContext ucpContext = null;
UcpListener ucpListener = null;
// if UCX socket is already created, use that
// this happens in mpi clusters
Stack<Closeable> ucxObjects = (Stack<Closeable>) WorkerEnvironment.getSharedValue("ucxSocketsForFreePorts");
if (ucxObjects != null && ucxObjects.size() > 2) {
// todo: handle the case when there are multiple ucp sockets
while (!ucxObjects.isEmpty()) {
Closeable ucxObj = ucxObjects.pop();
if (ucxObj instanceof UcpListener) {
ucpListener = (UcpListener) ucxObj;
} else if (ucxObj instanceof UcpContext) {
ucpContext = (UcpContext) ucxObj;
} else if (ucxObj instanceof UcpWorker) {
ucpWorker = (UcpWorker) ucxObj;
} else {
LOG.warning("Unrecognized UCX object: " + ucxObj);
}
}
// add them to closeables
closeables.push(ucpContext);
closeables.push(ucpWorker);
closeables.push(ucpListener);
// create UCX objects
} else {
ucpContext = initUcpContext();
this.closeables.push(ucpContext);
this.ucpWorker = ucpContext.newWorker(new UcpWorkerParams().requestThreadSafety());
this.closeables.push(ucpWorker);
UcpListenerParams ucpListenerParams = new UcpListenerParams().setSockAddr(new InetSocketAddress(iWorkerController.getWorkerInfo().getWorkerIP(), iWorkerController.getWorkerInfo().getPort()));
// start listener
try {
ucpListener = ucpWorker.newListener(ucpListenerParams);
closeables.push(ucpListener);
} catch (org.openucx.jucx.UcxException ucxEx) {
throw new Twister2RuntimeException("Can not start TWSUCXChannel.", ucxEx);
}
}
try {
// wait till everyone add listeners
iWorkerController.waitOnBarrier();
} catch (TimeoutException e) {
LOG.log(Level.SEVERE, "Failed to wait on barrier", e);
}
// create end points
for (JobMasterAPI.WorkerInfo worker : iWorkerController.getJoinedWorkers()) {
if (worker.getWorkerID() != workerId) {
UcpEndpoint ucpEndpoint = ucpWorker.newEndpoint(new UcpEndpointParams().setSocketAddress(new InetSocketAddress(worker.getWorkerIP(), worker.getPort())));
this.endpoints.put(worker.getWorkerID(), ucpEndpoint);
this.closeables.push(ucpEndpoint);
}
}
}
use of org.openucx.jucx.ucp.UcpListener in project twister2 by DSC-SPIDAL.
the class TWSUCXChannel method findFreeUcxPorts.
/**
* create Ucx sockets and return the ports
* save the created objects in the the static map of WorkerEnvironment,
* so that they can be reused when TWSUCXChannel is initialized
* @param portNames
* @param wIP
* @return
*/
public static Map<String, Integer> findFreeUcxPorts(List<String> portNames, InetAddress wIP) {
UcpContext context = initUcpContext();
Stack<Closeable> ucxObjects = new Stack<>();
ucxObjects.push(context);
UcpWorker ucpWorker = context.newWorker(new UcpWorkerParams().requestThreadSafety());
ucxObjects.push(ucpWorker);
Map<String, Integer> freePorts = new HashMap<>();
for (String portName : portNames) {
UcpListener ucpListener = createUcpListener(ucpWorker, wIP);
ucxObjects.push(ucpListener);
int port = ucpListener.getAddress().getPort();
LOG.fine("workerPort for ucx channel: " + port);
freePorts.put(portName, ucpListener.getAddress().getPort());
}
WorkerEnvironment.putSharedValue("ucxSocketsForFreePorts", ucxObjects);
return freePorts;
}
Aggregations