I am writing a C++ program that does a brute-force search for closed Knight's tours. The code is here.
I would like to parallelize this using OpenMP. My problem is to do this in a way that creates a sufficient degree of parallelism. Currently the relevant portion of my code looks like this
#pragma omp parallel for reduction(+:count) if (depth==4)
for (size_t i=0;i<g.neighbours[last].size();i++){
auto n = g.neighbours[last][i];
// See if n can be used to extend or complete the tour
The if (depth==4) is my attempt to make sure that not too many parallel tasks are created but on the other hand enough are created to keep all processors busy. Setting depth==2 does not change the runtime of the program.
This does not seem to be working out. For a 3x12 problem, on my dual-core processor the total CPU time consumed by the OpenMP version is around 130s whereas a single-threaded version without OpenMP takes around 40s of CPU time.
I would appreciate suggestions on how better to use OpenMP or reasons why it is unsuitable for this problem.
