Parallelizing "while loop" dependent data algorithm

Discuss the OpenMP 3.0 API Specifications with the OpenMP Arch. Review Board. (Read Only)

Parallelizing "while loop" dependent data algorithm

Postby ahfan_022003 » Thu Jun 25, 2009 7:09 am

I tried many ways to parallelize the "while loop" dependent data algorithm but it seem no solution. The algorithm data flow is look like this:

while ( u <= u_end)
{
task_1 ( u, x, y, z );
task_2 ( x, y, z, a, b, c );
task_3 ( a, b, c, u_next );
task_4 ( u_next, d, e, f );
task_5 ( d, e, f, j, k, l);
}

task_1, task_2 and task_3 are running first using 1st processor using the first value of u. When it arrive at task_4 which is the next calculation of the value u, task_4 and task_5 are running by 1st processor while at the same time algorithm is going back to task_1, task_2 and task_3 which are running by using 2nd processor.

Hope anyone can help me with this matter. Thank you
ahfan_022003
 
Posts: 2
Joined: Mon Jun 22, 2009 4:58 pm

Re: Parallelizing "while loop" dependent data algorithm

Postby lfm » Thu Jul 16, 2009 8:11 am

This forum is intended for direct communication with the OpenMP ARB regarding language specification issues and so forth, not for general questions. I suspect you would get more response if you posted in the general forum.

It sounds like you are setting up a pipeline. You could formulate this with OpenMP task constructs, or possibly as a for loop. In either case you will need to provide synchronization between the tasks (e.g., using a lock).

Hope this helps.

-- Larry
lfm
 
Posts: 135
Joined: Sun Oct 21, 2007 4:58 pm
Location: OpenMP ARB

Re: Parallelizing "while loop" dependent data algorithm

Postby ahfan_022003 » Wed Jul 29, 2009 12:16 am

Thanks for your info. May i know where i can find an example using lock routine? Or can you give me some example? I had searched in internet but the example only using a simple lock.

#include <stdio.h>
#include <omp.h>

void skip(int i) {}
void work(int i) {}

int main()
{
omp_lock_t lck1;
int id;
omp_init_lock(&lck1);
omp_set_num_threads(8);

#pragma omp parallel shared(lck1) private(id)
{
id = omp_get_thread_num();
omp_set_lock(&lck1);
/* only one thread at a time can execute this printf */
printf("My thread id is %d.\n", id);
omp_unset_lock(&lck1);

while (! omp_test_lock(&lck1)) {
skip(id); /* we do not yet have the lock, so we must do something else */
}

work(id); /* we now have the lock and can do the work */
omp_unset_lock(&lck1);
}
omp_destroy_lock(&lck1);

return 0;
}

Only this example i found in OpenMP 3.0 specification.


-fakhri-
ahfan_022003
 
Posts: 2
Joined: Mon Jun 22, 2009 4:58 pm


Return to OpenMP 3.0 API Specifications

Who is online

Users browsing this forum: Google [Bot] and 0 guests

cron