00001 /* 00002 * ################################################################ 00003 * 00004 * ProActive: The Java(TM) library for Parallel, Distributed, 00005 * Concurrent computing with Security and Mobility 00006 * 00007 * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis 00008 * Contact: proactive@objectweb.org 00009 * 00010 * This library is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Lesser General Public 00012 * License as published by the Free Software Foundation; either 00013 * version 2.1 of the License, or any later version. 00014 * 00015 * This library is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public 00021 * License along with this library; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 * USA 00024 * 00025 * Initial developer(s): The ProActive Team 00026 * http://www.inria.fr/oasis/ProActive/contacts.html 00027 * Contributor(s): 00028 * 00029 * ################################################################ 00030 */ 00031 package org.objectweb.proactive.core.process.mpi; 00032 00033 import org.objectweb.proactive.core.process.AbstractExternalProcessDecorator; 00034 import org.objectweb.proactive.core.process.ExternalProcess; 00035 import org.objectweb.proactive.core.process.UniversalProcess; 00036 import org.objectweb.proactive.core.process.filetransfer.FileDependant; 00037 import org.objectweb.proactive.core.process.filetransfer.FileTransferDefinition; 00038 00039 00047 public abstract class MPIProcess extends AbstractExternalProcessDecorator 00048 implements FileDependant { 00049 00053 private static final long serialVersionUID = 1L; 00054 protected static final String DEFAULT_HOSTSFILENAME_PATH = ".machinefile"; 00055 protected static final String DEFAULT_MPICOMMAND_PATH = "/usr/bin/mpirun"; 00056 protected static final String DEFAULT_FILE_LOCATION = System.getProperty( 00057 "user.home"); 00058 public final static String DEFAULT_SSH_COPYPROTOCOL = "scp"; 00059 protected static final String DEFAULT_HOSTS_NUMBER = "1"; 00060 protected int jobID; 00061 protected String mpiCommandOptions = null; 00062 protected String hostsFileName = DEFAULT_HOSTSFILENAME_PATH; 00063 protected String mpiFileName = null; 00064 protected String localPath = DEFAULT_FILE_LOCATION; 00065 protected String remotePath = null; 00066 protected String hostsNumber = DEFAULT_HOSTS_NUMBER; 00067 00068 // TEMPORARY 00069 protected String PROACTIVE_HOME = DEFAULT_FILE_LOCATION + "/ProActive"; 00070 00075 public MPIProcess() { 00076 super(); 00077 setCompositionType(COPY_FILE_AND_APPEND_COMMAND); 00078 this.command_path = DEFAULT_MPICOMMAND_PATH; 00079 FILE_TRANSFER_DEFAULT_PROTOCOL = DEFAULT_SSH_COPYPROTOCOL; 00080 } 00081 00082 public MPIProcess(ExternalProcess targetProcess) { 00083 super(targetProcess); 00084 this.command_path = DEFAULT_MPICOMMAND_PATH; 00085 FILE_TRANSFER_DEFAULT_PROTOCOL = DEFAULT_SSH_COPYPROTOCOL; 00086 } 00087 00088 /* (non-Javadoc) 00089 * @see org.objectweb.proactive.core.process.UniversalProcess#getProcessId() 00090 */ 00091 public String getProcessId() { 00092 return "mpi"; 00093 } 00094 00095 protected String internalBuildCommand() { 00096 return buildMPICommand(); 00097 } 00098 00099 protected String buildMPICommand() { 00100 StringBuilder mpiSubCommand = new StringBuilder(); 00101 mpiSubCommand.append(this.command_path).append(" "); 00102 if (remotePath != null) { 00103 mpiSubCommand.append("-machinefile").append(" "); 00104 mpiSubCommand.append(remotePath).append("/"); 00105 mpiSubCommand.append(this.hostsFileName).append(" "); 00106 mpiSubCommand.append("-nolocal").append(" "); 00107 } 00108 00109 mpiSubCommand.append("-np").append(" "); 00110 mpiSubCommand.append(this.hostsNumber).append(" "); 00111 if (remotePath != null) { 00112 mpiSubCommand.append(remotePath).append("/"); 00113 } else { 00114 mpiSubCommand.append(localPath).append("/"); 00115 } 00116 mpiSubCommand.append(this.mpiFileName).append(" "); 00117 if (mpiCommandOptions != null) { 00118 mpiSubCommand.append(this.mpiCommandOptions).append(" "); 00119 } 00120 return mpiSubCommand.toString(); 00121 } 00122 00123 public FileTransferDefinition getFileTransfertDefiniton() { 00124 FileTransferDefinition ft = new FileTransferDefinition("mpiProcess"); 00125 if (remotePath != null) { 00126 ft.addFile(localPath + "/" + hostsFileName, 00127 remotePath + "/" + hostsFileName); 00128 // System.out.println(localPath + "/" + hostsFileName + " --> " + 00129 // remotePath + "/" + hostsFileName); 00130 } 00131 00132 return ft; 00133 } 00134 00135 /************************************************************************ 00136 * GETTERS AND SETTERS * 00137 ************************************************************************/ 00138 public UniversalProcess getFinalProcess() { 00139 return this.getTargetProcess(); 00140 } 00141 00145 public String getMpiFileName() { 00146 return mpiFileName; 00147 } 00148 00152 public void setMpiFileName(String mpiFileName) { 00153 this.mpiFileName = mpiFileName; 00154 } 00155 00159 public String getHostsFileName() { 00160 return hostsFileName; 00161 } 00162 00166 public void setHostsFileName(String hostsFileName) { 00167 this.hostsFileName = hostsFileName; 00168 } 00169 00173 public String getHostsNumber() { 00174 return this.hostsNumber; 00175 } 00176 00180 public void setHostsNumber(String hostsNumber) { 00181 this.hostsNumber = hostsNumber; 00182 } 00183 00187 public String getLocalPath() { 00188 return localPath; 00189 } 00190 00194 public void setLocalPath(String localPath) { 00195 this.localPath = localPath; 00196 } 00197 00201 public String getRemotePath() { 00202 return remotePath; 00203 } 00204 00208 public void setRemotePath(String remotePath) { 00209 this.remotePath = remotePath; 00210 } 00211 00215 public void setMpiCommandOptions(String mpiCommandOptions) { 00216 this.mpiCommandOptions = mpiCommandOptions; 00217 } 00218 00222 public String getMpiCommandOptions() { 00223 return this.mpiCommandOptions; 00224 } 00225 00227 public boolean isDependent() { 00228 return true; 00229 } 00230 00231 public int getNodeNumber() { 00232 return 0; 00233 } 00234 00235 /****************************************************************************************** 00236 * END OF GETTERS AND SETTERS * 00237 ******************************************************************************************/ 00238 }