mpiMainTest.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 1999, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** ****************************************************************** */
00020                                                                         
00021 // $Revision: 1.1 $
00022 // $Date: 2006/01/13 19:35:27 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/tcl/mpiMainTest.cpp,v $
00024 
00025 extern "C" {
00026 #include <tcl.h>
00027 #include <tk.h>
00028 }
00029 
00030 #include <stdio.h>
00031 #include <string.h>
00032 
00033 #include <PartitionedDomain.h>
00034 #include <MPI_MachineBroker.h>
00035 #include <ShadowSubdomain.h>
00036 #include <ActorSubdomain.h>
00037 #include <FEM_ObjectBroker.h>
00038 
00039 extern PartitionedDomain theDomain;
00040 
00041 extern int OPS_PARALLEL_PROCESSING;
00042 extern int OPS_NUM_SUBDOMAINS;
00043 extern bool OPS_PARTITIONED;
00044 extern FEM_ObjectBroker *OPS_OBJECT_BROKER;
00045 extern MachineBroker    *OPS_MACHINE;
00046 
00047 static MPI_MachineBroker *theMachineBroker = 0;
00048 
00049 #include <Node.h>
00050 #include <Matrix.h>
00051 
00052 int
00053 main(int argc, char **argv)
00054 {
00055   FEM_ObjectBroker theBroker;
00056   MPI_MachineBroker theMachine(&theBroker, argc, argv);
00057   theMachineBroker = &theMachine;
00058 
00059   int rank = theMachine.getPID();
00060   int np = theMachine.getNP();
00061 
00062   //
00063   // depending on rank we do something
00064   //
00065   if (rank != 0) {
00066 
00067     //
00068     // on slave processes we spin waiting to create & run actors
00069     //
00070     fprintf(stderr, "Slave Process Running\n");
00071     theMachine.runActors();
00072 
00073   } else {
00074 
00075     //
00076     // on process 0 we create some ShadowSubdomains & then start the OpenSees interpreter
00077     //
00078     fprintf(stderr, "Master Process Running OpenSees Interpreter\n");   
00079 
00080     //
00081     // set some global parameters
00082     //
00083     OPS_OBJECT_BROKER = &theBroker;
00084     OPS_MACHINE = &theMachine;
00085     OPS_PARALLEL_PROCESSING = np;
00086     OPS_NUM_SUBDOMAINS = np - 1;
00087     OPS_PARTITIONED    = false;
00088     Channel  **OPS_theChannels = 0;
00089     OPS_theChannels = new Channel *[OPS_NUM_SUBDOMAINS];
00090     Subdomain **OPS_theSubdomains = 0;
00091     OPS_theSubdomains = new Subdomain *[OPS_NUM_SUBDOMAINS];
00092 
00093     // start the remote actors
00094     for (int i=1; i<=OPS_NUM_SUBDOMAINS; i++) {
00095       ShadowSubdomain *theSubdomain = new ShadowSubdomain(i, 
00096                                                           *OPS_MACHINE, 
00097                                                           *OPS_OBJECT_BROKER);
00098       theDomain.addSubdomain(theSubdomain);
00099       OPS_theChannels[i-1] = theSubdomain->getChannelPtr();
00100       OPS_theSubdomains[i-1] = theSubdomain;
00101     }
00102 
00103     Subdomain *theSubdomain = OPS_theSubdomains[0];
00104     Node *node1 = new Node(1, 2,   0.0,  0.0);
00105     Node *node2 = new Node(2, 2, 144.0,  0.0);
00106     Node *node3 = new Node(3, 2, 168.0,  0.0);    
00107     Node *node4 = new Node(4, 2,  72.0, 96.0);        
00108     Matrix mass(2,2); mass(0,0)=1.0; mass(1,1)=2.0;
00109     node1->setMass(mass);
00110     node2->setMass(mass);
00111 
00112     theSubdomain->addNode(node1);
00113     theSubdomain->addExternalNode(node2);
00114     //    theDomain.addNode(node2);
00115     theDomain.addNode(node3);
00116     theDomain.addNode(node4);
00117     theDomain.Print(opserr);
00118 
00119     // some clean up to shut the remotes down if still running
00120     theDomain.clearAll();
00121 
00122     // test that everything is shutting down correctly
00123   }
00124 
00125   //
00126   // mpi clean up
00127   //
00128 
00129   theMachine.shutdown();
00130 
00131   fprintf(stderr, "Process Terminating %d\n", rank);
00132 
00133   return 0;
00134 }
00135 
00136 int OpenSeesExit(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
00137 {
00138   //
00139   // mpi clean up
00140   //
00141 
00142   if (theMachineBroker != 0) {
00143     theMachineBroker->shutdown();
00144     fprintf(stderr, "Process Terminating\n");
00145   }
00146 
00147   return 0;
00148 }

Generated on Mon Oct 23 15:05:30 2006 for OpenSees by doxygen 1.5.0