00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.mpi;
00032
00033 import org.apache.log4j.Logger;
00034
00035 import org.objectweb.proactive.ActiveObjectCreationException;
00036 import org.objectweb.proactive.ProActive;
00037 import org.objectweb.proactive.core.descriptor.data.VirtualNode;
00038 import org.objectweb.proactive.core.node.NodeException;
00039 import org.objectweb.proactive.core.util.log.Loggers;
00040 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00041
00042 import java.io.IOException;
00043
00044 import java.util.ArrayList;
00045 import java.util.Hashtable;
00046
00047
00048 public class MPISpmdProxy implements MPISpmd, java.io.Serializable {
00049 protected final static Logger MPI_PROXY_LOGGER = ProActiveLogger.getLogger(Loggers.MPI);
00050
00052 private String status = MPIConstants.MPI_DEFAULT_STATUS;
00053
00055 private String name;
00056
00058 private MPISpmdImpl target;
00059
00063 public MPISpmdProxy(VirtualNode vn) throws RuntimeException {
00064 try {
00065 target = (MPISpmdImpl) ProActive.newActive(MPISpmdImpl.class.getName(),
00066 new Object[] { vn });
00067 } catch (ActiveObjectCreationException e) {
00068 e.printStackTrace();
00069 } catch (NodeException e) {
00070 e.printStackTrace();
00071 }
00072 name = target.getName();
00073 MPI_PROXY_LOGGER.debug("[MPI Proxy] creating MPI SPMD active object: " +
00074 name);
00075 MPI_PROXY_LOGGER.debug("[MPI Proxy] status : " + status);
00076
00077 try {
00078 ProActive.setImmediateService(target, "killMPI");
00079 ProActive.setImmediateService(target, "getStatus");
00080 ProActive.setImmediateService(target, "isFinished");
00081 ProActive.setImmediateService(target, "getSpmdClassesParams");
00082 ProActive.setImmediateService(target, "getSpmdClasses");
00083 ProActive.setImmediateService(target, "getClassesParams");
00084 ProActive.setImmediateService(target, "getClasses");
00085 } catch (IOException e) {
00086 e.printStackTrace();
00087 }
00088 }
00089
00094 public MPIResult startMPI() throws IllegalMPIStateException {
00095 MPI_PROXY_LOGGER.debug(
00096 "[MPI Proxy] call start method on active object ");
00097 MPI_PROXY_LOGGER.debug("[MPI Proxy] status : " + status);
00098
00099 if (status.equals(MPIConstants.MPI_UNSTARTED)) {
00100 setStatus(MPIConstants.MPI_RUNNING);
00101 return target.startMPI();
00102 } else {
00103 ProActive.terminateActiveObject(target, true);
00104 throw new IllegalMPIStateException(
00105 "!!! ERROR: cannot start MPI process " + this.name +
00106 " Caused by: MPI process has already been started once ");
00107 }
00108 }
00109
00115 public MPIResult reStartMPI() throws IllegalMPIStateException {
00116 MPI_PROXY_LOGGER.debug(
00117 "[MPI Proxy] call reStart method on active object ");
00118 MPI_PROXY_LOGGER.debug("[MPI Proxy] status : " + status);
00119
00120 checkTerminationStatus();
00121
00122 if (!status.equals(MPIConstants.MPI_UNSTARTED)) {
00123 setStatus(MPIConstants.MPI_RUNNING);
00124 target.reinitProcess();
00125 return target.startMPI();
00126 } else {
00127 ProActive.terminateActiveObject(target, true);
00128 throw new IllegalMPIStateException(
00129 "!!! ERROR: cannot restart MPI process " + this.name +
00130 " Caused by: no mpi process has been started once before");
00131 }
00132 }
00133
00139 public boolean killMPI() {
00140 MPI_PROXY_LOGGER.debug("[MPI Proxy] Kill MPI Process ");
00141 checkTerminationStatus();
00142
00143 if (status.equals(MPIConstants.MPI_RUNNING)) {
00144 setStatus(MPIConstants.MPI_KILLED);
00145 return target.killMPI();
00146 }
00147 else if (status.equals(MPIConstants.MPI_FINISHED) ||
00148 status.equals(MPIConstants.MPI_KILLED)) {
00149 return false;
00150 }
00151
00152 else {
00153 ProActive.terminateActiveObject(target, true);
00154 throw new IllegalMPIStateException(
00155 "!!! ERROR: cannot kill MPI process " + this.name +
00156 " Caused by: no mpi process has been started once before!");
00157 }
00158 }
00159
00163 public String getStatus() {
00164 checkTerminationStatus();
00165 return status;
00166 }
00167
00172 public void setMPICommandArguments(String arguments) {
00173 target.setMPICommandArguments(arguments);
00174 }
00175
00180 public String getName() {
00181 return this.name;
00182 }
00183
00184 public String toString() {
00185 StringBuilder sb = new StringBuilder(target.toString());
00186 sb.append("\n Status: ");
00187 sb.append(getStatus());
00188 return sb.toString();
00189 }
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 private void setStatus(String status) {
00202 this.status = status;
00203 }
00204
00205 private void checkTerminationStatus() {
00206 if (target.isFinished() && (!status.equals(MPIConstants.MPI_FINISHED)) &&
00207 (!status.equals(MPIConstants.MPI_KILLED))) {
00208 status = MPIConstants.MPI_FINISHED;
00209 }
00210 }
00211
00212 public VirtualNode getVn() {
00213 return this.target.getVn();
00214 }
00215
00216
00217
00218
00219 public void newActiveSpmd(String cl) {
00220 this.target.newActiveSpmd(cl);
00221 }
00222
00223 public void newActiveSpmd(String cl, Object[] params) {
00224 this.target.newActiveSpmd(cl, params);
00225 }
00226
00227 public void newActiveSpmd(String cl, Object[][] params) {
00228 this.target.newActiveSpmd(cl, params);
00229 }
00230
00231 public void newActive(String cl, Object[] params, int rank) {
00232 this.target.newActive(cl, params, rank);
00233 }
00234
00235 public ArrayList getClasses() {
00236 return this.target.getClasses();
00237 }
00238
00239 public ArrayList getSpmdClasses() {
00240 return this.target.getSpmdClasses();
00241 }
00242
00243 public Hashtable getClassesParams() {
00244 return this.target.getClassesParams();
00245 }
00246
00247 public Hashtable getSpmdClassesParams() {
00248 return this.target.getSpmdClassesParams();
00249 }
00250
00251 public String getRemoteLibraryPath() {
00252 return this.target.getRemoteLibraryPath();
00253 }
00254 }