00001 /* @HEADER@ */ 00002 // ************************************************************************ 00003 // 00004 // Sundance 00005 // Copyright (2005) Sandia Corporation 00006 // 00007 // Copyright (year first published) Sandia Corporation. Under the terms 00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 00009 // retains certain rights in this software. 00010 // 00011 // This library is free software; you can redistribute it and/or modify 00012 // it under the terms of the GNU Lesser General Public License as 00013 // published by the Free Software Foundation; either version 2.1 of the 00014 // License, or (at your option) any later version. 00015 // 00016 // This library is distributed in the hope that it will be useful, but 00017 // WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 // Lesser General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU Lesser General Public 00022 // License along with this library; if not, write to the Free Software 00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00024 // USA 00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 00026 // Sandia National Laboratories, Livermore, California, USA 00027 // 00028 // ************************************************************************ 00029 /* @HEADER@ */ 00030 00031 #include "Sundance.hpp" 00032 00033 int main(int argc, char** argv) 00034 { 00035 try 00036 { 00037 /* Initialization */ 00038 Sundance::init(&argc, &argv); 00039 00040 /* ---- BEGIN CODE BODY --- */ 00041 00042 /* The main simulation code goes here. In this example, all we do 00043 * is to print some information about the processor ranks. */ 00044 00045 MPIComm comm = MPIComm::world(); 00046 00047 /* Print a header from the root processor only. Although this executes on 00048 * all processors, anything written to the output stream Out::root() 00049 * is ignored on all non-root processors (rank != 0). 00050 * After writing, synchronize to keep this message from getting jumbled 00051 * together with the subsequent messages. 00052 */ 00053 Out::root() << "Example: getting started" << endl; 00054 comm.synchronize(); 00055 00056 /* Every processor now speaks up and identifies itself */ 00057 int myRank = comm.getRank(); 00058 int nProc = comm.getNProc(); 00059 Out::os() << "Processor " << myRank 00060 << " of " << nProc << " checking in" << endl; 00061 00062 /* ---- END CODE BODY --- */ 00063 00064 /* Test success or failure. Most examples you'll see will do this 00065 * as part of the Trilinos regression testing system. 00066 * If you write a simulation code that won't become part of Trilinos, 00067 * you often can bypass this step. 00068 * 00069 * Here the test is a trival one: every processor's rank must be 00070 * smaller than the total number of processors. If this fails, 00071 * your MPI installation is probably broken! 00072 * */ 00073 Sundance::passFailTest(myRank < nProc); 00074 } 00075 catch(std::exception& e) /* exception handling */ 00076 { 00077 cerr << "exception!" << endl; 00078 Sundance::handleException(e); 00079 } 00080 /* Finalization */ 00081 Sundance::finalize(); 00082 00083 return Sundance::testStatus(); 00084 }