I am fairly new with Java Threads, I normally use C with it comes to parallelization. To parallelize algorithm that has the same pattern as the one it follows:
void traverse(node* p)
{
if (p->left)
#pragma omp task // p is firstprivate by default
traverse(p->left);
if (p->right)
#pragma omp task // p is firstprivate by default
traverse(p->right);
}
I would use the task directive of openMP, for example.
Task Description
When a thread encounters a task construct, a task is generated from
the code for the associated structured block. The encountering thread
may immediately execute the task, or defer its execution. In the
latter case, any thread in the team may be assigned the task.
Completion of the task can be guaranteed using task synchronization
constructs. A task construct may be nested inside an outer task, but
the task region of the inner task is not a part of the task region of
the outer task.
My question is:
How I could implement this same idea (task) with Java Threads?
The pragmas of OpenMP do make parallelization a little easier.
In Java, you would first need to create a class that implements Runnable.
– example: public Class Traverse implements Runnable
You then just neew to create the class and call ‘run’ to start the thread.