MPI_MachineBroker.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: 2003/08/29 07:17:38 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/actor/machineBroker/MPI_MachineBroker.cpp,v $
00024                                                                         
00025                                                                         
00026 // Written: fmk
00027 // Revision: A
00028 
00029 
00030 #include <FEM_ObjectBroker.h>
00031 #include <MPI_MachineBroker.h>
00032 #include <MPI_Channel.h>
00033 #include <ID.h>
00034 
00035 #include <mpi.h>
00036 
00037 MPI_MachineBroker::MPI_MachineBroker(FEM_ObjectBroker *theBroker, int argc, char **argv)
00038   :MachineBroker(theBroker)
00039 {
00040   MPI_Init(&argc, &argv);
00041   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
00042   MPI_Comm_size(MPI_COMM_WORLD, &size);
00043 
00044   theChannels = new MPI_Channel *[size];
00045   for (int i=0; i<size; i++) {
00046       theChannels[i] = new MPI_Channel(i);
00047   }
00048   usedChannels = new ID(size);
00049   usedChannels->Zero();
00050 }
00051 
00052 
00053 MPI_MachineBroker::~MPI_MachineBroker()
00054 {
00055   for (int i=0; i<size; i++) {
00056       delete theChannels[i]; 
00057   }
00058 
00059   delete [] theChannels;
00060   delete usedChannels;
00061 
00062   MPI_Finalize();
00063 }
00064 
00065 
00066 int 
00067 MPI_MachineBroker::getPID(void)
00068 {
00069   return rank;
00070 }
00071 
00072 
00073 int 
00074 MPI_MachineBroker::getNP(void)
00075 {
00076   return size;
00077 }
00078 
00079 
00080 
00081 Channel *
00082 MPI_MachineBroker::getMyChannel(void)
00083 {
00084   return theChannels[0];
00085 }
00086 
00087 
00088 
00089 Channel *
00090 MPI_MachineBroker::getRemoteProcess(void)
00091 {
00092   if (rank != 0) {
00093     opserr << "MPI_MachineBroker::getRemoteProcess() - child process cannot not yet allocate processes\n";
00094     return 0;
00095   }
00096       
00097   for (int i=0; i<size; i++)
00098     if (i != rank)
00099       if ((*usedChannels)(i) == 0) {
00100         (*usedChannels)(i) = 1;
00101         return theChannels[i];
00102       }
00103   
00104   // no processes available
00105   return 0;
00106 }
00107 
00108 
00109 
00110 int 
00111 MPI_MachineBroker::freeProcess
00112 (Channel *theChannel)
00113 {
00114   for (int i=0; i<size; i++)
00115     if (i != rank)
00116       if (theChannels[i] == theChannel) {
00117         (*usedChannels)(i) = 0;
00118         return 0;
00119       }
00120   
00121   // channel not found!
00122   return -1;
00123 }
00124 

Generated on Mon Oct 23 15:04:56 2006 for OpenSees by doxygen 1.5.0