I need to run some code from I: biginteger := 1
to some biginteger value in parallel. Since it's a biginteger I am not able to use parallel for and it seems like omp for
does not work with a while loop.
Got a little problem with the code trying to improve it working mono.... Once I'm done fixing, I'll put an update in here explaining everything in details.
I can only comment on the OpenMP part of the question and it indeed you can only (directly) parallelize OpenMP loops that use regular integers (int, long, ...) as the type for the loop counter. This is for all OpenMP loop statements such as for
, taskloop
, etc.
One thing that you can always do is a pattern like this (assuming that the big integer is called bigint
and has overloaded arithmetic operators). The following is just pseudo-code to show the idea, you'll have to adjust it to the actual API you want to use:
void process_bigint() {
binint i;
bigint start = some_start_value();
binint end = some_end_value();
i = start;
#pragma omp parallel
#pragma omp single
while(i < end) {
#pragma omp task firstprivate(i)
{
process_bigint(i);
}
}
}
The main idea behind this is that you manually iterate through the space of big integer numbers that you want to process. This is done by one thread. For each number (or a bunch of number; pattern will be sightly more complex), you spawn an OpenMP task to do the actual work for the number.
How well this works depends a bit on what you will actually do for each of the number. If it's just a few operations, task creation might be too costly and you'd need to spawn a task for a group of numbers.
Hope that helps!
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加