use of edu.rit.mp.ChannelGroup in project ffx by mjschnie.
the class Comm method init.
// Exported operations.
/**
* Initialize the PJ message passing middleware. Certain Java system
* properties specify the middleware's behavior; these properties are
* typically given on the Java command line with the <TT>"-D"</TT> flag. For
* further information, see class {@linkplain PJProperties}.
*
* @param args Command line arguments.
*
* @exception NullPointerException (unchecked exception) Thrown if
* <TT>args</TT> is null.
* @exception IllegalArgumentException (unchecked exception) Thrown if the
* value of one of the Java system properties is illegal.
* @exception IOException Thrown if an I/O error occurred.
*/
public static void init(String[] args) throws IOException {
// Verify preconditions.
if (args == null) {
throw new NullPointerException("Comm.init(): args is null");
}
// Get the job backend object.
JobBackend backend = JobBackend.getJobBackend();
if (backend == null) {
// We're running on the frontend processor.
// Prepare constructor arguments for the Job Frontend object.
String username = System.getProperty("user.name");
int Nn = PJProperties.getPjNn();
int Np = PJProperties.getPjNp();
int Nt = PJProperties.getPjNt();
boolean hasFrontendComm = false;
// Examine the call stack to find the main program class name.
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
StackTraceElement bottom = stack[stack.length - 1];
if (!bottom.getMethodName().equals("main")) {
throw new IllegalStateException("Comm.init(): Not called from main program");
}
String mainClassName = bottom.getClassName();
// Set up the Job Frontend object.
JobFrontend frontend = null;
try {
frontend = new JobFrontend(username, Nn, Np, Nt, hasFrontendComm, mainClassName, args);
// We were able to contact the Job Scheduler.
// Run the job frontend in this process, then exit.
frontend.run();
System.exit(0);
} catch (JobSchedulerException exc) {
// We were not able to contact the Job Scheduler.
// System.err.println(" No Job Scheduler at " + PJProperties.getPjHost() + ":" + PJProperties.getPjPort() + ", running in this (one) process");
// Set up world communicator.
theWorldCommunicator = new Comm(/*size */
1, /*rank */
0, /*host */
"<unknown>", /*channelgroup*/
new ChannelGroup(), /*address */
new InetSocketAddress[] { new InetSocketAddress(0) });
}
} else {
// We're running on a backend processor.
// Set up world communicator.
theWorldCommunicator = new Comm(/*size */
backend.getK(), /*rank */
backend.getRank(), /*host */
backend.getBackendHost(), /*channelgroup*/
backend.getWorldChannelGroup(), /*address */
backend.getWorldAddress());
}
}
use of edu.rit.mp.ChannelGroup in project ffx by mjschnie.
the class Comm method createComm.
/**
* Create a new communicator. <I>Every</I> process in this communicator must
* call the <TT>createComm()</TT> method. Each process passes true or false
* for the <TT>participate</TT> argument to state whether the process will
* participate in the new communicator. At least one process must
* participate in the new communicator. Messages to set up the new
* communicator are sent to all processes in this communicator, using the
* given message tag.
* <P>
* In processes participating in the new communicator, the new communicator
* is returned. The participating processes appear in the same order by rank
* in the new communicator as in this communicator. The process can call the
* new communicator's <TT>rank()</TT> method to determine the process's rank
* in the new communicator.
* <P>
* In processes not participating in the new communicator, null is returned.
*
* @param participate True if this process will participate in the new
* communicator; false otherwise.
* @param tag Message tag.
*
* @return New communicator if this process will participate in the new
* communicator; null otherwise.
*
* @exception IOException Thrown if an I/O error occurred.
*/
public Comm createComm(boolean participate, int tag) throws IOException {
// Set up array of socket addresses for all processes.
InetSocketAddress[] address = new InetSocketAddress[mySize];
ObjectBuf<InetSocketAddress>[] addressbuf = ObjectBuf.sliceBuffers(address, new Range(0, mySize - 1).subranges(mySize));
// Create channel group for new communicator, if participating.
ChannelGroup channelgroup = null;
InetSocketAddress myaddress = null;
if (participate) {
channelgroup = new ChannelGroup(new InetSocketAddress(myChannelGroup.listenAddress().getAddress(), 0));
myaddress = channelgroup.listenAddress();
address[myRank] = myaddress;
}
// All-gather channel group socket addresses into every process.
allGather(tag, addressbuf[myRank], addressbuf);
// Close up gaps in the socket address array if any.
int off = 0;
int newsize = 0;
int newrank = -1;
for (int i = 0; i < mySize; ++i) {
if (address[i] == null) {
++off;
} else {
if (i == myRank) {
newrank = i - off;
}
address[i - off] = address[i];
++newsize;
}
}
// Verify size of new communicator.
if (newsize == 0) {
throw new IOException("Comm.createComm(): No processes in communicator");
}
// Return new communicator if participating.
if (participate) {
return new Comm(newsize, newrank, myHost, channelgroup, address);
} else // Return null if not participating.
{
return null;
}
}
Aggregations