00001 /*************************************************************************** 00002 * Copyright (C) 2005 by Robot Group Leipzig * 00003 * martius@informatik.uni-leipzig.de * 00004 * fhesse@informatik.uni-leipzig.de * 00005 * der@informatik.uni-leipzig.de * 00006 * guettler@informatik.uni-leipzig.de * 00007 * * 00008 * This program is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation; either version 2 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program; if not, write to the * 00020 * Free Software Foundation, Inc., * 00021 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00022 *************************************************************************** 00023 * * 00024 * DESCRIPTION * 00025 * 00026 * * 00027 * * 00028 * $Log: simulationtasksupervisor.h,v $ 00029 * Revision 1.3 2009/09/17 14:13:09 guettler 00030 * - some bugfixes for critical sections 00031 * - support to set number of threads per core 00032 * 00033 * Revision 1.2 2009/08/21 09:49:07 robot12 00034 * (guettler) support for tasked simulations. 00035 * - use the simulation template_taskedSimulations. 00036 * - merged (not completely) from lpzrobots_tasked. 00037 * - graphics is supported, but only for one simulation of a pool 00038 * 00039 * Revision 1.1.2.1 2009/08/11 15:59:20 guettler 00040 * - support for tasked simulations, does not yet work with graphics 00041 * - in development state 00042 * * 00043 * * 00044 **************************************************************************/ 00045 #ifndef _SIMULATIONTASKSUPERVISOR_H_ 00046 #define _SIMULATIONTASKSUPERVISOR_H_ 00047 00048 #include "simulationtask.h" 00049 #include <string> 00050 00051 namespace osg 00052 { 00053 class ArgumentParser; 00054 } 00055 00056 00057 namespace lpzrobots 00058 { 00059 00060 class LpzRobotsViewer; 00061 00062 class SimulationTaskSupervisor 00063 { 00064 public: 00065 00066 /** 00067 * Returns the singleton instance of this class. 00068 * There is no way to instantiate yourself this class. 00069 * @param simTaskHandle The global SimulationTaskHandle were you can put in your needed data. 00070 * This handle is shared by all parallel running simulations. 00071 * @return the singleton instance of this class 00072 */ 00073 static inline SimulationTaskSupervisor* getInstance() 00074 { 00075 if(singletonInstance==0) 00076 singletonInstance = new SimulationTaskSupervisor(); 00077 return singletonInstance; 00078 } 00079 00080 /** 00081 * Destroys the singleton instance of this class. 00082 */ 00083 static void destroyInstance() 00084 { 00085 if (singletonInstance!=0) 00086 { 00087 delete singletonInstance; 00088 singletonInstance=0; 00089 } 00090 } 00091 00092 static void setSimTaskHandle(SimulationTaskHandle& _simTaskHandle) 00093 { 00094 simTaskHandle= &_simTaskHandle; 00095 } 00096 00097 static void setTaskedSimCreator(TaskedSimulationCreator& _taskedSimCreator) 00098 { 00099 taskedSimCreator = &_taskedSimCreator; 00100 } 00101 00102 /** 00103 * Sets the number of total threads running at one time. 00104 * @param numberThreads 00105 */ 00106 static void setNumberThreads(int numberThreads); 00107 00108 /** 00109 * Sets the number of threads created per core. The default value is 1. 00110 * So if your machine has e.g. 4 cores, 4 threads are created. 00111 * If you have much code which must be synchronized, it may be 00112 * useful to increase the number of threads per core, 2 is a good value. 00113 * @param numberThreadsPerCore 00114 */ 00115 static void setNumberThreadsPerCore(int numberThreadsPerCore); 00116 00117 /** 00118 * Creates one SimulationTask with taskId=SimulationTaskHandle.simTaskList.size(). 00119 * @param argc count of arguments in argv 00120 * @param argv array of arguments, given to Simulation when the tasks starts 00121 */ 00122 virtual void createSimTask() 00123 { 00124 SimulationTask* simTask = new SimulationTask(simTaskList.size()); 00125 SimulationTaskSupervisor::simTaskList.push_back(simTask); 00126 } 00127 00128 /** 00129 * Same as createSimTask, but create more than one task at once. 00130 * taskIds assigned in ascending order. 00131 * @param taskCount number of tasks to create 00132 * @param argc count of arguments in argv 00133 * @param argv array of arguments, given to Simulation when the tasks starts 00134 */ 00135 virtual void createSimTasks(int taskCount) 00136 { 00137 for (int i=0; i<taskCount; i++) 00138 createSimTask(); 00139 } 00140 00141 /** 00142 * Runs all generated SimulationTasks. 00143 */ 00144 virtual void runSimTasks(int* argc, char** argv); 00145 00146 /** 00147 * Sets a suffix to be appended to the window name to identify your simTask 00148 */ 00149 virtual void setSimTaskNameSuffix(std::string name); 00150 00151 protected: 00152 00153 SimulationTaskSupervisor() {} 00154 00155 virtual ~SimulationTaskSupervisor() {} 00156 00157 static SimulationTaskSupervisor* singletonInstance; 00158 static SimulationTaskHandle* simTaskHandle; 00159 static TaskedSimulationCreator* taskedSimCreator; 00160 static std::vector<SimulationTask*> simTaskList; 00161 static int* argc; 00162 static char** argv; 00163 static osg::ArgumentParser* parser; 00164 static LpzRobotsViewer* viewer; 00165 static std::string nameSuffix; 00166 00167 00168 }; 00169 00170 } // end namespace lpzrobots 00171 00172 #endif /* _SIMULATIONTASKSUPERVISOR_H_ */