EvolvingObjects
|
00001 /* 00002 (c) Thales group, 2012 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Lesser General Public 00006 License as published by the Free Software Foundation; 00007 version 2 of the License. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Lesser General Public License for more details. 00013 00014 You should have received a copy of the GNU Lesser General Public 00015 License along with this library; if not, write to the Free Software 00016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 Contact: http://eodev.sourceforge.net 00018 00019 Authors: 00020 Benjamin Bouvier <benjamin.bouvier@gmail.com> 00021 */ 00022 # ifndef __EO_TERMINATE_H__ 00023 # define __EO_TERMINATE_H__ 00024 00025 # include "eoMpi.h" 00026 00027 namespace eo 00028 { 00029 namespace mpi 00030 { 00039 struct DummySendTaskFunction : public SendTaskFunction<void> 00040 { 00041 void operator()( int _ ) 00042 { 00043 ++_; 00044 } 00045 }; 00046 00050 struct DummyHandleResponseFunction : public HandleResponseFunction<void> 00051 { 00052 void operator()( int _ ) 00053 { 00054 ++_; 00055 } 00056 }; 00057 00061 struct DummyProcessTaskFunction : public ProcessTaskFunction<void> 00062 { 00063 void operator()() 00064 { 00065 // nothing! 00066 } 00067 }; 00068 00072 struct DummyIsFinishedFunction : public IsFinishedFunction<void> 00073 { 00074 bool operator()() 00075 { 00076 return true; 00077 } 00078 }; 00079 00083 struct DummyJobStore : public JobStore<void> 00084 { 00085 using JobStore<void>::_stf; 00086 using JobStore<void>::_hrf; 00087 using JobStore<void>::_ptf; 00088 using JobStore<void>::_iff; 00089 00090 DummyJobStore() 00091 { 00092 _stf = new DummySendTaskFunction; 00093 _stf->needDelete( true ); 00094 _hrf = new DummyHandleResponseFunction; 00095 _hrf->needDelete( true ); 00096 _ptf = new DummyProcessTaskFunction; 00097 _ptf->needDelete( true ); 00098 _iff = new DummyIsFinishedFunction; 00099 _iff->needDelete( true ); 00100 } 00101 00102 void* data() { return 0; } 00103 }; 00104 00108 struct EmptyJob : public OneShotJob<void> 00109 { 00116 EmptyJob( AssignmentAlgorithm& algo, int masterRank ) : 00117 OneShotJob<void>( algo, masterRank, *(new DummyJobStore) ) 00118 // the job store is deleted on destructor 00119 { 00120 // empty 00121 } 00122 00123 ~EmptyJob() 00124 { 00125 std::vector< int > idles = assignmentAlgo.idles(); 00126 for(unsigned i = 0, size = idles.size(); i < size; ++i) 00127 { 00128 comm.send( idles[i], Channel::Commands, Message::Kill ); 00129 } 00130 delete & this->store; 00131 } 00132 }; 00133 00137 } 00138 } 00139 00140 # endif // __EO_TERMINATE_H__