libeblearntools
/home/rex/ebltrunk/tools/libeblearntools/include/mpijob.h
00001 /***************************************************************************
00002  *   Copyright (C) 2011 by Pierre Sermanet   *
00003  *   pierre.sermanet@gmail.com   *
00004  *   All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Redistribution under a license not approved by the Open Source 
00014  *       Initiative (http://www.opensource.org) must display the 
00015  *       following acknowledgement in all advertising material:
00016  *        This product includes software developed at the Courant
00017  *        Institute of Mathematical Sciences (http://cims.nyu.edu).
00018  *     * The names of the authors may not be used to endorse or promote products
00019  *       derived from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 
00022  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00023  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00024  * DISCLAIMED. IN NO EVENT SHALL ThE AUTHORS BE LIABLE FOR ANY
00025  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00026  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00028  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00029  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031  ***************************************************************************/
00032 
00033 #ifndef MPIJOB_H_
00034 #define MPIJOB_H_
00035 
00036 #ifdef __MPI__
00037 #include <mpi.h>
00038 #include <boost/archive/text_oarchive.hpp>
00039 #include <boost/archive/text_iarchive.hpp>
00040 #include <boost/serialization/string.hpp>
00041 #include <boost/mpi.hpp>
00042 #endif
00043 
00044 #include "job.h"
00045 
00046 using namespace std;
00047 
00048 namespace ebl {
00049 
00051   class EXPORT mpijob : public job {
00052   public:
00058     mpijob(configuration &conf, const char *oconffname = NULL,
00059            bool resume = false);
00061     virtual ~mpijob();
00062 
00064     virtual void run();
00065     
00066   protected:
00067 
00069     virtual void run_child();
00070 
00072     // members
00073   protected:
00074   };
00075 
00077   // mpijob manager
00078 
00080   class EXPORT mpijob_manager : public job_manager {
00081   public:
00084     mpijob_manager(int argc, char **argv);
00086     virtual ~mpijob_manager();
00093     virtual bool read_metaconf(const char *fname, const string *tstamp = NULL,
00094                                const char *resume_name = NULL,
00095                                bool resumedir = false,
00096                                bool nomax = false, int maxjobs = -1);
00098     virtual void prepare(bool reset_progress = false);
00100     virtual void run(bool force_start = false);
00102     virtual uint world_size();
00104     virtual bool is_master();
00105 
00106   protected:
00109     virtual void run_master();
00111     virtual void stop_all();
00114     virtual bool assign(uint jobid, uint slave_id);
00117     void jinfos(int running[]);
00119     virtual void run_slave();
00120 
00121     // members /////////////////////////////////////////////////////////////////
00122   protected:
00123 #ifdef __MPI__
00124     boost::mpi::communicator world;
00125     boost::mpi::environment env;
00126 #endif
00127     int rank;
00128     int jslots;
00129     int id_running; 
00130     bool use_master; 
00131   };
00132 
00133 } // end namespace ebl
00134 
00135 #endif /* MPIJOB_H_ */