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

# APPSPACK_Conveyor.cpp

Go to the documentation of this file.

    00001 // $Id: APPSPACK_Conveyor.cpp,v 1.11 2004/04/12 17:43:55 tgkolda Exp $
    00002 // $Source: /space/CVS-Acro/acro/packages/appspack/appspack/src/APPSPACK_Conveyor.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_Conveyor.hpp"
    00039
    00040 APPSPACK::Conveyor::Conveyor(Parameter::List& params,
    00041                              const Vector& scaling_in,
    00042                              Executor::Interface& executor_in) :
    00043
    00044   executor(executor_in),
    00045   cache(params, scaling_in),
    00046   doSync(params.getParameter("Synchronous", false)),
    00047   maxQueue(params.getParameter("Max Queue Size", 0)),
    00048   minReturn(params.getParameter("Minimum Exchange Return", 1)),
    00049   maxReturn(params.getParameter("Maximum Exchange Return", max(minReturn, 1000) ))
    00050 {
    00051 }
    00052
    00053 APPSPACK::Conveyor::~Conveyor()
    00054 {
    00055   queueList.prune();
    00056   pendingList.prune();
    00057 }
    00058
    00059 const APPSPACK::Counter& APPSPACK::Conveyor::getCounter() const
    00060 {
    00061   return counter;
    00062 }
    00063
    00064 void APPSPACK::Conveyor::exchange(List& exchangeList)
    00065 {
    00066   Point* ptr;
    00067   Value value;
    00068   int tag;
    00069   bool isf;
    00070   double f;
    00071   string msg;
    00072
    00073   // Add the new points to the queue.  Has the side effect of emptying
    00074   // the exchangeList.
    00075   queueList.insertList(exchangeList);
    00076
    00077   while (((queueList.size() > 0) || (pendingList.size() > 0)) && ((doSync) || (exchangeList.size() < minReturn)))
    00078   {
    00079     // Try to submit as many items as possible to the executor
    00080     while ((queueList.isNotEmpty()) && (executor.isWaiting()))
    00081     {
    00082       ptr = queueList.pop();
    00083       if ( cache.isCached( ptr->getX(), value) )
    00084       {
    00085         counter.incrementCached();
    00086         ptr->setCachedFunctionValue(value, counter.getCountString());
    00087         exchangeList.push(ptr);
    00088       }
    00089       else
    00090       {
    00091         executor.spawn( ptr->getX(), ptr->getTag() );
    00092         pendingList.push(ptr);
    00093       }
    00094     }
    00095
    00096     // Process items coming out of the executor
    00097     int id;
    00098     while (((id = executor.recv(tag,isf,f,msg)) != 0) && ((doSync) || (exchangeList.size() < maxReturn)))
    00099     {
    00100       counter.incrementEvaluated(id, msg);
    00101       value.setValueTo(isf, f);
    00102       ptr = pendingList.pop(tag);
    00103       ptr->setEvaluatedFunctionValue(value, counter.getCountString());
    00104       cache.insert( ptr->getX(), value );
    00105       exchangeList.push(ptr);
    00106     }
    00107
    00108   }
    00109 }
    00110
    00111 void APPSPACK::Conveyor::prune()
    00112 {
    00113   queueList.prune(maxQueue);
    00114 }
    00115
    00116 void APPSPACK::Conveyor::print() const
    00117 {
    00118   executor.print();
    00119 }

© 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