00001 /******************************************************************************* 00002 Copyright (c) 2011, Yahoo! Inc. 00003 All rights reserved. 00004 00005 Redistribution and use of this software in source and binary forms, 00006 with or without modification, are permitted provided that the following 00007 conditions are met: 00008 00009 * Redistributions of source code must retain the above 00010 copyright notice, this list of conditions and the 00011 following disclaimer. 00012 00013 * Redistributions in binary form must reproduce the above 00014 copyright notice, this list of conditions and the 00015 following disclaimer in the documentation and/or other 00016 materials provided with the distribution. 00017 00018 * Neither the name of Yahoo! Inc. nor the names of its 00019 contributors may be used to endorse or promote products 00020 derived from this software without specific prior 00021 written permission of Yahoo! Inc. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00024 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00025 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00026 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00027 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00028 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00029 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00030 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00031 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00032 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 00035 The Initial Developer of the Original Code is Shravan Narayanamurthy. 00036 ******************************************************************************/ 00037 /* 00038 * Synchronizer.h 00039 * 00040 * 00041 * Created on: 07-Jan-2011 00042 * 00043 */ 00044 00045 #ifndef SYNCHRONIZER_H_ 00046 #define SYNCHRONIZER_H_ 00047 00048 #include "Synchronizer_Helper.h" 00049 00050 //!The synchronization strategy that 00051 //!uses the Synchronizer_Helper to perform the 00052 //!concrete synchronization steps. 00053 /** 00054 * It provides slots, so to say, for synchronization 00055 * and calls the Synchronizer_Helper to perform its 00056 * duties for that slot. 00057 * 00058 * This greatly reduces the burden on the model writer 00059 * 00060 * So whenever a model needs to be scaled by providing 00061 * a distributed inferencing solution, all the model writer 00062 * has to do is write a Synchronizer_Helper. 00063 * 00064 * This is a default synchronization strategy provided and 00065 * users can implement their own strategy by extending this 00066 * 00067 * The main aim is to run the inferencing locally while 00068 * keeping the model in sync globally through the use of 00069 * this Synchronizer and a Distributed Map 00070 */ 00071 class Synchronizer { 00072 public: 00073 Synchronizer(Synchronizer_Helper&); 00074 virtual ~Synchronizer(); 00075 00076 //!The synchronization strategy 00077 void synchronize(); 00078 00079 //!Set that all iterations of the Execution_Strategy 00080 //!have been done 00081 void set_all_iters_done(); 00082 00083 //!Check if the Execution_Strategy has finished 00084 bool is_all_iters_done(); 00085 00086 private: 00087 Synchronizer_Helper& _sync_helper; 00088 bool _all_iters_done; 00089 00090 }; 00091 00092 #endif /* SYNCHRONIZER_H_ */