EvolvingObjects
|
00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- 00002 00003 //----------------------------------------------------------------------------- 00004 // eoApply.h 00005 // (c) Maarten Keijzer 2000 00006 /* 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with this library; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 00021 Contact: todos@geneura.ugr.es, http://geneura.ugr.es 00022 mak@dhi.dk 00023 */ 00024 //----------------------------------------------------------------------------- 00025 00026 #ifndef _apply_h 00027 #define _apply_h 00028 00029 #include <utils/eoParallel.h> 00030 #include <utils/eoParser.h> 00031 #include <utils/eoLogger.h> 00032 #include <eoFunctor.h> 00033 #include <vector> 00034 00035 #ifdef _OPENMP 00036 #include <omp.h> 00037 #endif 00038 00044 template <class EOT> 00045 void apply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop) 00046 { 00047 size_t size = _pop.size(); 00048 00049 #ifdef _OPENMP 00050 00051 double t1 = 0; 00052 00053 if ( eo::parallel.enableResults() ) 00054 { 00055 t1 = omp_get_wtime(); 00056 } 00057 00058 if (!eo::parallel.isDynamic()) 00059 { 00060 #pragma omp parallel for if(eo::parallel.isEnabled()) //default(none) shared(_proc, _pop, size) 00061 #ifdef _MSC_VER 00062 //Visual Studio supports only OpenMP version 2.0 in which 00063 //an index variable must be of a signed integral type 00064 for (long long i = 0; i < size; ++i) { _proc(_pop[i]); } 00065 #else // _MSC_VER 00066 for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); } 00067 #endif 00068 } 00069 else 00070 { 00071 #pragma omp parallel for schedule(dynamic) if(eo::parallel.isEnabled()) 00072 #ifdef _MSC_VER 00073 //Visual Studio supports only OpenMP version 2.0 in which 00074 //an index variable must be of a signed integral type 00075 for (long long i = 0; i < size; ++i) { _proc(_pop[i]); } 00076 #else // _MSC_VER 00077 //doesnot work with gcc 4.1.2 00078 //default(none) shared(_proc, _pop, size) 00079 for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); } 00080 #endif 00081 } 00082 00083 if ( eo::parallel.enableResults() ) 00084 { 00085 double t2 = omp_get_wtime(); 00086 eoLogger log; 00087 log << eo::file(eo::parallel.prefix()) << t2 - t1 << ' '; 00088 } 00089 00090 #else // _OPENMP 00091 00092 for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); } 00093 00094 #endif // !_OPENMP 00095 } 00096 00103 // template <class EOT> 00104 // void omp_apply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop) 00105 // { 00106 // size_t size = _pop.size(); 00107 // #pragma omp parallel for if(eo::parallel.isEnabled()) 00108 // //doesnot work with gcc 4.1.2 00109 // //default(none) shared(_proc, _pop, size) 00110 // for (size_t i = 0; i < size; ++i) 00111 // { 00112 // _proc(_pop[i]); 00113 // } 00114 // } 00115 00121 // template <class EOT> 00122 // void omp_dynamic_apply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop) 00123 // { 00124 // size_t size = _pop.size(); 00125 // #pragma omp parallel for if(eo::parallel.isEnabled()) schedule(dynamic) 00126 // //doesnot work with gcc 4.1.2 00127 // //default(none) shared(_proc, _pop, size) 00128 // for (size_t i = 0; i < size; ++i) 00129 // { 00130 // _proc(_pop[i]); 00131 // } 00132 // } 00133 00134 #endif