Reputation: 129
Currently I have a knight's tour algorithm that is working.
I uses a combination of:
The algorithm does the following:
Checks to see if the board is solved (all squares visited)
If true: return true
else proceed:
Make a set of possible moves from current positions
Sort the set based on the number of moves available from those positions.
Go through the set. (Recursive call made here)
If returned True:
Set Solution board to appropriate number
Return true
else
go back to last position
return false.
It works okay. It is not the best solution.
I am trying to increase the speed using parallelization, in particular, using C++ threading (#include<thread>
).
What is the algorithm for this? So far the only ways I have tried have false sharing issues, shared memory issues or won't run at all.
Upvotes: 0
Views: 920
Reputation: 129
Granted this is for C++, after calling the #include<thread>
header, a simple way of creating threads is:
#include <iostream>
#include <thread>
void testThread()
{
std::cout<<"Thread\n";
}
int main(int argc, char * argv[])
{
std::testThread t(testThread);
t.join();
return 0;
}
The std::testThread t(testThread);
calls the thread creation while t.join();
joins them after completion. But this is all without using locks. If I were you I would go over same examples online - there are a ton of resources - that show how to implement locks in a safe manor.
A thing to note is that you must make sure that the sequential version of the code can actually benefit from being run in parallel since thread creation can be costly.
Upvotes: 1