I wrote a parallelized version of for_each in c++. My problem is, it works successfully under MSVC and gcc compliers, but for some reason the code fails using an Intel compiler.
template<class T, class Function>
Function parallel_for_each(std::vector< T> & obj, Function f)
int size = obj.size();
#pragma omp parallel for firstprivate(f) shared(obj)
for (int i = 0; i < size; i++)
My understanding is that the firstprivate directive will initialize a copy of f that is identical to the copy of f I throw at it for each thread. However, what is happening is that some of the values which are initialized in the constructor do not get initialized in the other threads. Is there some other directive I am supposed to use?
Again, the code works fine under MSVC (2008 edition) and gcc (4.0). Fails under Intel 10.1 compiler.