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

cex_master.cpp

Go to the documentation of this file.
00001 // $Id: cex_master.cpp,v 1.1 2006/06/30 19:14:31 tgkolda Exp $ 
00002 // $Source: /space/CVS-Acro/acro/packages/appspack/appspack/example-custom-executor/cex_master.cpp,v $ 
00003 
00036 #include "mpi.h"                            // <-- Provides MPI
00037 #include "msgtags.hpp"                      // <-- Provides the message tags
00038 #include "executor.hpp"                     // <-- Provides user-defined custom executor
00039 #include "APPSPACK_Solver.hpp"              // <-- Provides APPSPACK::Solver
00040 #include "APPSPACK_Vector.hpp"              // <-- Provides APPSPACK::Vector 
00041 #include "APPSPACK_Constraints_Linear.hpp"  // <-- Provides APPSPACK::Constraints::Linear
00042 
00044 void master(int argc, char* argv[], int nprocs)
00045 {
00046   // *** Parse the command line ***
00047 
00048   int n;                        // Problem size
00049   sscanf(argv[1],"%d",&n);
00050   
00051   // *** Intialize the workers by sending the problem size to each ***
00052   // Note: Must have a corresponding recv on the worker
00053 
00054   for (int i = 1; i < nprocs; i ++)
00055     MPI_Send(&n, 1, MPI_INT, i, SIZE, MPI_COMM_WORLD);
00056   
00057   // *** Create and fill the parameter list ***
00058   
00059   APPSPACK::Parameter::List params;
00060 
00061   APPSPACK::Vector initialx(n, 1.0/n);
00062   params.sublist("Solver").setParameter("Initial X", initialx);
00063 
00064   // Be sure to do casts on any ambiguous constants, such as in this case
00065 
00066   params.sublist("Solver").setParameter("Debug", static_cast<int>(3));
00067   params.sublist("Solver").setParameter("Step Tolerance", static_cast<double>(0.0001));
00068 
00069   APPSPACK::Vector lowerbounds(n, -1.0);
00070   params.sublist("Linear").setParameter("Lower", lowerbounds);
00071 
00072   APPSPACK::Vector upperbounds(n, 3.0);
00073   params.sublist("Linear").setParameter("Upper", upperbounds);
00074   
00075   // *** Instantiate the custom executor ***
00076 
00077   CustomExecutor executor(n,nprocs);
00078   
00079   // *** Instantiate the bounds ***
00080 
00081   APPSPACK::Constraints::Linear linear(params.sublist("Linear"));
00082   
00083   // *** Create the solver ***
00084 
00085   APPSPACK::Solver solver(params.sublist("Solver"), executor, linear);
00086   
00087   // *** Run the solver ***
00088 
00089   APPSPACK::Solver::State state = solver.solve();
00090   
00091   // *** Send a termination command to every worker ***
00092 
00093   // Note: The worker needs to keep checking for the quit message
00094 
00095   for (int i = 1; i < nprocs; i ++)
00096     MPI_Send(&n, 1, MPI_INT, i, QUIT, MPI_COMM_WORLD);
00097 
00098 }

 

© Sandia Corporation | Site Contact | Privacy and Security

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