Commit 6c3465b8 authored by Alvarez, Gonzalo's avatar Alvarez, Gonzalo
Browse files

Parallelizer2: openmp driver

parent 123629f1
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
#ifndef PARALLELIZER2OPENMP_H
#define PARALLELIZER2OPENMP_H
#include "Vector.h"
#include <omp.h>

namespace PsimagLite {

template<typename = int>
class Parallizer2 {

public:

	Parallizer2(SizeType threads) : threads_(threads)
	{
		omp_set_num_threads(threads);
	}

	template<typename SomeLambdaType>
	void parallelFor(SizeType start, SizeType end, const SomeLambdaType& lambda)
	{
#pragma omp parallel for
		for (SizeType i = start; i < end; ++i)
			lambda(i, omp_get_thread_num());
	}

	SizeType numberOfThreads() const
	{
		return omp_get_num_threads();
	}

	String name() const { return "openmp"; }

private:

	SizeType threads_;
};
}
#endif // PARALLELIZER2OPENMP_H