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_main.cpp

Go to the documentation of this file.
00001 // $Id: cex_main.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_main.cpp,v $ 
00003 
00024 #include <iostream>             // <-- for cout and cerr
00025 #include "mpi.h"                // <-- Provides MPI
00026 
00027 // forward declarations for functions defined in master.cpp and
00028 // worker.cpp, respectively.
00029 void master(int argc, char* argv[], int nprocs);
00030 void worker();
00031 
00033 int main(int argc, char* argv[])
00034 {
00035   // Start MPI
00036   MPI_Init(&argc, &argv);
00037 
00038   // Get my rank 
00039   int rank;
00040   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
00041 
00042   // Get number of processors
00043   int nprocs;
00044   MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
00045 
00046   // Check that there is at least one worker 
00047   if (nprocs < 2)
00048   {
00049     std::cerr << "Error: This program requires at least 2 processes." << std::endl;
00050     MPI_Finalize();
00051     return 1;
00052   }
00053   
00054   // Check the number of input arguments 
00055   if (argc < 2)
00056   {
00057     if (rank == 0)
00058       std::cout << "Usage: " << argv[0] << " <problem size>" << std::endl;
00059     MPI_Finalize();
00060     return 1;
00061   }
00062 
00063   // Run main program
00064   if (rank == 0)        
00065   {
00066     master(argc, argv, nprocs);
00067   }
00068   else                  
00069   {
00070     worker();
00071   } 
00072 
00073   // Exit MPI
00074   MPI_Finalize();
00075 
00076 } // main
00077 

 

© 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