Sandia Home Sandia Home
Main Page | Publications | Downloads | Configuration | Running the Code | Solver Parameters | FAQ | Namespace List | Class Hierarchy | 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.13 2006/06/30 01:42:08 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   int tag;
00068   bool isf;
00069   Vector f;
00070   string msg;
00071 
00072   // Add the new points to the queue.  Has the side effect of emptying
00073   // the exchangeList.
00074   queueList.insertList(exchangeList);
00075 
00076   while (((queueList.size() > 0) || (pendingList.size() > 0)) && ((doSync) || (exchangeList.size() < minReturn)))
00077   {
00078     // Try to submit as many items as possible to the executor
00079     while ((queueList.isNotEmpty()) && (executor.isWaiting()))
00080     {
00081       ptr = queueList.pop();
00082       if ( cache.isCached( ptr->getX(), f) )
00083       {
00084         counter.incrementCached();
00085         ptr->setCachedFunctionValue(f, counter.getCountString());
00086         exchangeList.push(ptr);
00087       }
00088       else
00089       {
00090         executor.spawn( ptr->getX(), ptr->getTag() );
00091         pendingList.push(ptr);
00092       }
00093     }
00094     
00095     // Process items coming out of the executor
00096     int id;
00097     while (((id = executor.recv(tag,f,msg)) != 0) && ((doSync) || (exchangeList.size() < maxReturn)))
00098     {
00099       counter.incrementEvaluated(id, msg);
00100       ptr = pendingList.pop(tag);
00101       ptr->setEvaluatedFunctionValue(f, counter.getCountString());
00102       cache.insert(ptr->getX(),f);
00103       exchangeList.push(ptr);
00104     }
00105 
00106   }
00107 }
00108 
00109 void APPSPACK::Conveyor::prune()
00110 {
00111   queueList.prune(maxQueue);
00112 }
00113 
00114 void APPSPACK::Conveyor::print() const
00115 {
00116   executor.print();
00117 }

 

© Sandia Corporation | Site Contact | Privacy and Security

Generated on Fri Feb 16 10:33:34 2007 for APPSPACK 5.0.1 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2002