use of edu.rit.pj.Comm in project ffx by mjschnie.
the class Main method startParallelJava.
/**
* Start up the Parallel Java communication layer.
*/
private static void startParallelJava(String[] args) {
try {
Comm.init(args);
Comm world = Comm.world();
rank = world.rank();
processes = world.size();
} catch (Exception e) {
String message = String.format(" Exception starting up the Parallel Java communication layer.");
logger.log(Level.WARNING, message, e.toString());
}
}
use of edu.rit.pj.Comm in project ffx by mjschnie.
the class ForceFieldEnergyOpenMM method loadPlatform.
/**
* Load an OpenMM Platform
*/
private void loadPlatform(Platform requestedPlatform) {
// Print out the OpenMM Version.
Pointer version = OpenMM_Platform_getOpenMMVersion();
logger.log(Level.INFO, " OpenMM Version: {0}", version.getString(0));
// Print out the OpenMM plugin directory.
Pointer pluginDir = OpenMM_Platform_getDefaultPluginsDirectory();
String pluginDirString = pluginDir.getString(0);
if (SystemUtils.IS_OS_WINDOWS) {
pluginDirString = pluginDirString + "/plugins";
}
logger.log(Level.INFO, " OpenMM Plugin Dir: {0}", pluginDirString);
/**
* Load plugins and print out plugins.
*
* Call the method twice to avoid a bug where not all platforms are list
* after the first call.
*/
PointerByReference plugins = OpenMM_Platform_loadPluginsFromDirectory(pluginDirString);
OpenMM_StringArray_destroy(plugins);
plugins = OpenMM_Platform_loadPluginsFromDirectory(pluginDirString);
int numPlugins = OpenMM_StringArray_getSize(plugins);
logger.log(Level.INFO, " Number of OpenMM Plugins: {0}", numPlugins);
boolean cuda = false;
for (int i = 0; i < numPlugins; i++) {
String pluginString = stringFromArray(plugins, i);
logger.log(Level.INFO, " Plugin: {0}", pluginString);
if (pluginString.toUpperCase().contains("AMOEBACUDA")) {
cuda = true;
}
}
OpenMM_StringArray_destroy(plugins);
/**
* Extra logging to print out plugins that failed to load.
*/
if (logger.isLoggable(Level.FINE)) {
PointerByReference pluginFailers = OpenMM_Platform_getPluginLoadFailures();
int numFailures = OpenMM_StringArray_getSize(pluginFailers);
for (int i = 0; i < numFailures; i++) {
String pluginString = stringFromArray(pluginFailers, i);
logger.log(Level.FINE, " Plugin load failure: {0}", pluginString);
}
OpenMM_StringArray_destroy(pluginFailers);
}
int numPlatforms = OpenMM_Platform_getNumPlatforms();
logger.log(Level.INFO, " Number of OpenMM Platforms: {0}", numPlatforms);
/**
* for (int i = 0; i < numPlatforms; i++) { PointerByReference
* currentPlatform = OpenMM_Platform_getPlatform(i); Pointer
* platformName = OpenMM_Platform_getName(currentPlatform);
* logger.log(Level.INFO, " Platform: {0}", platformName.getString(0));
* OpenMM_Platform_destroy(currentPlatform); }
*/
String defaultPrecision = "mixed";
String precision = molecularAssembly.getForceField().getString(ForceField.ForceFieldString.PRECISION, defaultPrecision).toLowerCase();
precision = precision.replace("-precision", "");
switch(precision) {
case "double":
case "mixed":
case "single":
logger.info(String.format(" Using precision level %s", precision));
break;
default:
logger.info(String.format(" Could not interpret precision level %s, defaulting to %s", precision, defaultPrecision));
precision = defaultPrecision;
break;
}
Comm world = Comm.world();
int size = world.size();
int defDeviceIndex = 0;
if (size > 1) {
int rank = world.rank();
CompositeConfiguration props = molecularAssembly.getProperties();
// 0/no-arg would indicate "just put everything on device specified by CUDA_DEVICE".
// TODO: Get the number of CUDA devices from the CUDA API as the alternate default.
int numCudaDevices = props.getInt("numCudaDevices", 0);
if (numCudaDevices > 0) {
defDeviceIndex = rank % numCudaDevices;
logger.info(String.format(" Placing energy from rank %d on device %d", rank, defDeviceIndex));
}
}
int deviceID = molecularAssembly.getForceField().getInteger(ForceField.ForceFieldInteger.CUDA_DEVICE, defDeviceIndex);
String deviceIDString = Integer.toString(deviceID);
if (cuda && requestedPlatform != Platform.OMM_REF) {
platform = OpenMM_Platform_getPlatformByName("CUDA");
OpenMM_Platform_setPropertyDefaultValue(platform, pointerForString("CudaDeviceIndex"), pointerForString(deviceIDString));
OpenMM_Platform_setPropertyDefaultValue(platform, pointerForString("Precision"), pointerForString(precision));
logger.info(String.format(" Selected OpenMM AMOEBA CUDA Platform (Device ID: %d)", deviceID));
} else {
platform = OpenMM_Platform_getPlatformByName("Reference");
logger.info(" Selected OpenMM AMOEBA Reference Platform");
}
}
use of edu.rit.pj.Comm in project ffx by mjschnie.
the class Runner method main.
// Main program.
/**
* Main program.
*
* @param args an array of {@link java.lang.String} objects.
* @throws java.lang.Exception if any.
*/
public static void main(String[] args) throws Exception {
if (args.length != 1) {
usage();
}
// Initialize world communicator.
Comm.init(args);
world = Comm.world();
rank = world.rank();
// Set up worker team.
team = new WorkerTeam();
// Master process sets up job generator.
if (rank == team.masterRank()) {
omitted = new HashSet<Integer>();
// Assume argument is a checkpoint file name and try to read it.
Scanner scanner = null;
try {
scanner = new Scanner(new File(args[0]));
} catch (IOException exc) {
}
// Read checkpoint file.
if (scanner != null) {
while (scanner.hasNextLine()) {
Scanner linescanner = new Scanner(scanner.nextLine());
String word;
int jobnum;
if (!linescanner.hasNext()) {
continue;
}
word = linescanner.next();
if (!word.equals("***")) {
continue;
}
if (!linescanner.hasNext()) {
continue;
}
word = linescanner.next();
if (word.equals("Generator")) {
if (!linescanner.hasNext()) {
continue;
}
if (generatorExpression == null) {
generatorExpression = linescanner.next();
}
} else if (word.equals("Job")) {
if (!linescanner.hasNextInt()) {
continue;
}
jobnum = linescanner.nextInt();
if (!linescanner.hasNext()) {
continue;
}
word = linescanner.next();
if (word.equals("finished")) {
omitted.add(jobnum);
}
}
}
scanner.close();
} else // Assume argument is a job generator constructor expression.
{
generatorExpression = args[0];
}
// Create job generator.
if (generatorExpression == null) {
stderr.printf("Runner: No job generator in checkpoint file %s%n", args[0]);
} else {
try {
generator = (JobGenerator) Instance.newInstance(generatorExpression);
stdout.printf("*** Generator %s%n", generatorExpression);
generator.omit(omitted);
} catch (Throwable exc) {
stderr.printf("Runner: Could not create job generator %s%n", generatorExpression);
exc.printStackTrace(stderr);
}
}
}
// Abort every process if job generator was not created.
BooleanItemBuf buf = BooleanBuf.buffer(generator != null);
world.broadcast(team.masterRank(), buf);
if (!buf.item) {
System.exit(1);
}
// Generate and run jobs.
team.execute(new WorkerRegion() {
public void run() throws Exception {
execute(generator, new WorkerIteration<Job>() {
public void sendTaskInput(Job job, Comm comm, int wRank, int tag) {
stdout.printf("*** Job %d started %s %s%n", job.getJobNumber(), new Date(), job.getDescription());
}
public void run(Job job) {
job.run();
}
public void receiveTaskOutput(Job job, Comm comm, int wRank, int tag) {
stdout.printf("*** Job %d finished %s%n", job.getJobNumber(), new Date());
}
});
}
});
if (rank == team.masterRank()) {
stdout.printf("*** All jobs finished%n");
}
}
use of edu.rit.pj.Comm in project ffx by mjschnie.
the class LogFormatter method format.
/**
* {@inheritDoc}
* <p>
* Unless debugging is turned on or the LogRecord is of level WARNING or
* greater, just return the message.
* <p>
* If more than one process is active, prepend the rank of the process to
* each line of the message.
*
* @since 1.0
*/
@Override
public String format(LogRecord record) {
String message = null;
if (debug || record.getLevel().intValue() >= warningLevel) {
message = super.format(record);
} else {
message = record.getMessage();
Object[] objects = record.getParameters();
message = MessageFormat.format(message, objects);
}
try {
Comm comm = Comm.world();
int size = comm.size();
int rank = comm.rank();
if (size > 1) {
if (mpiLogging) {
String[] lines = message.split("\n");
message = String.format(" [%d]%s", rank, lines[0]);
int numLines = lines.length;
for (int i = 1; i < numLines; i++) {
message = message.concat(String.format("\n [%d]%s", rank, lines[i]));
}
} else if (rank != 0) {
message = null;
}
}
} catch (Exception e) {
// If Comm.world does not exist, do not append the rank.
}
return message;
}
Aggregations