Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# APPSPACK_Executor_MPI.cpp

Go to the documentation of this file.

    00001 // $Id: APPSPACK_Executor_MPI.cpp,v 1.6 2003/11/26 16:27:11 tgkolda Exp $
    00002 // $Source: /space/CVS-Acro/acro/packages/appspack/appspack/src/APPSPACK_Executor_MPI.cpp,v $
    00003
    00004 //@HEADER
    00005 // ************************************************************************
    00006 //
    00007 //          APPSPACK: Asynchronous Parallel Pattern Search
    00008 //                 Copyright (2003) Sandia Corporation
    00009 //
    00010 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
    00011 // license for use of this work by or on behalf of the U.S. Government.
    00012 //
    00013 // This library is free software; you can redistribute it and/or modify
    00014 // it under the terms of the GNU Lesser General Public License as
    00015 // published by the Free Software Foundation; either version 2.1 of the
    00016 // License, or (at your option) any later version.
    00017 //
    00018 // This library is distributed in the hope that it will be useful, but
    00019 // WITHOUT ANY WARRANTY; without even the implied warranty of
    00020 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00021 // Lesser General Public License for more details.
    00022 //
    00023 // You should have received a copy of the GNU Lesser General Public
    00024 // License along with this library; if not, write to the Free Software
    00025 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
    00026 // USA.                                                                           .
    00027 //
    00028 // Questions? Contact Tammy Kolda (tgkolda@sandia.gov)
    00029 //
    00030 // ************************************************************************
    00031 //@HEADER
    00032
    00038 #include "APPSPACK_Executor_MPI.hpp"
    00039 #include "APPSPACK_GCI.hpp"
    00040
    00041 APPSPACK::Executor::MPI::MPI()
    00042 {
    00043   int nWorkers = GCI::getNumProcs() - 1;
    00044   workertag.resize(nWorkers);
    00045   for (int i = 0; i < nWorkers; i ++)
    00046     workertag[i] = -1;
    00047 }
    00048
    00049 APPSPACK::Executor::MPI::~MPI()
    00050 {
    00051 }
    00052
    00053 bool APPSPACK::Executor::MPI::isWaiting() const
    00054 {
    00055   for (int i = 0; i < workertag.size(); i ++)
    00056     if (workertag[i] == -1)
    00057       return true;
    00058
    00059   return false;
    00060 }
    00061
    00062 bool APPSPACK::Executor::MPI::spawn(const Vector& x_in, int tag_in)
    00063 {
    00064
    00065   for (int i = 0; i < workertag.size(); i ++)
    00066     if (workertag[i] == -1)
    00067     {
    00068       workertag[i] = tag_in;
    00069       GCI::initSend();
    00070       GCI::pack(tag_in);
    00071       GCI::pack(x_in);
    00072       GCI::send(Feval, i+1);
    00073       return true;
    00074     }
    00075
    00076   return false;
    00077 }
    00078
    00079 int APPSPACK::Executor::MPI::recv(int& tag_out, bool& isF_out, double& f_out, string& msg_out)
    00080 {
    00081   if (!GCI::probe(Feval))
    00082     return 0;
    00083
    00084   int junk;
    00085   int rank;
    00086
    00087   GCI::recv(Feval);
    00088   GCI::bufinfo(junk, rank);
    00089   GCI::unpack(tag_out);
    00090   GCI::unpack(isF_out);
    00091   GCI::unpack(f_out);
    00092   GCI::unpack(msg_out);
    00093
    00094   // Index into the tag array is the MPI rank minus one.
    00095   int idx = rank - 1;
    00096   workertag[idx] = -1;
    00097
    00098   return rank;
    00099 }
    00100
    00101 void APPSPACK::Executor::MPI::print() const
    00102 {
    00103   cout << "\n";
    00104   cout << "Using MPI Executor with " << workertag.size() << " workers" << endl;
    00105 }

© Sandia Corporation | Site Contact | Privacy and Security

Generated on Wed Dec 14 18:41:04 2005 for APPSPACK 4.0.2 by 1.3.8 written by Dimitri van Heesch, © 1997-2002