#pragma omp task

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

#pragma omp task

Postby Ranzeeta » Fri Mar 13, 2009 6:07 am

I have recently upgraded gcc version to gcc-4.3.2 in order to parallelize the "while" loop in openMP. I am using ubuntu 8.0.4 (hardy) with Inter core Quad CPU. Whenver i compile the program , i get the segmentatin fault error. Without use of openMP , tehre is no such problem. It would be a great help if you could post some examples to use "omp task" for nested while loop or any link . Is it possible to use such directives for Dynamic memory allocation??? I could not find any help so far.
Ranzeeta
 
Posts: 10
Joined: Wed Jan 07, 2009 6:56 am
Location: NRW , Germany

Re: #pragma omp task

Postby lfm » Sun Mar 15, 2009 9:40 am

Why don't you post a small example of your code that has a seg fault and we can see what is wrong with it.

Note that the General board is a more appropriate place for this question.
lfm
 
Posts: 135
Joined: Sun Oct 21, 2007 4:58 pm
Location: OpenMP ARB

Re: #pragma omp task

Postby Ranzeeta » Fri May 29, 2009 2:38 am

Hallo Everyone,

the following program is only the equivalent structure of my original program . In my original program, Do while loop was used . So, in order to change it to a "While" loop , i created the equivalent structure and changed the Do while loop to While loop. My final result in a sequential process is same with using "Do While" and "While" loop. But when i apply for my original program, the result is different. If anyone has an idea about it? could you please help me to parallelize this "While loop" using OpenMP.

with thanks


// calculate the first cogulated particle
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main (void)
{
double str[] = {1, 2, 3 , 4 , 5, 6 , 7 , 8 ,9,11,12,13,15,16,17,18,19,20,33,40,45,67,70};
int ntotal = 25;
double temp_sumsi=0.0;
int i= 0;
double maxr, Sipartner1;
srand (0.000001);
int ipartner1;
maxr = RAND_MAX + 1.0;
double rannum =(rand()/maxr);
while((temp_sumsi/2 < rannum) && (i <= ntotal))
// do
{
temp_sumsi = temp_sumsi + str[i];
ipartner1 = i;
i++;
/* Sipartner1 = str[ipartner1];
printf("the first partner : %d \n", Sipartner1);*/
} //while((temp_sumsi/2 < rannum) && (i <= ntotal));
Sipartner1 = str[ipartner1];
printf("the first partner : %f \n", Sipartner1);
printf (" the temp_sumsi : %f\n",temp_sumsi);


// find the second cogulated partner

double temp_sumj = 0.0;
int ipartner2;
int j =0;
double Si_partner2;
//double beta;
//do
while (((temp_sumsi- Sipartner1+temp_sumj)/2 < rannum) && (j<=ntotal))
{
ipartner2 = j;

if (j == ipartner1)
{
j++;
}
else
{
temp_sumj = temp_sumj + (5/pow(2.0,2));
j++;
//printf("temp_sumj:")
}
}
//while (((temp_sumsi- Sipartner1+temp_sumj)/2 < rannum) && (j<=ntotal));

//Si_partner2 = str[ipartner2];
printf("tempsum: %f\n",temp_sumj);
printf("second cogulated partner is : %d\n ", ipartner2);
return 0;

}
Ranzeeta
 
Posts: 10
Joined: Wed Jan 07, 2009 6:56 am
Location: NRW , Germany

Re: #pragma omp task

Postby kli » Fri May 29, 2009 6:09 am

I think the cause is the call of srand(0.000001) that expects unsigned int. As a result, rannum gets zero. The while loop is not executed because the condition is false. Since ipartner1 is not initialized, using it to index str can cause problem. If you have srand(123456) instead, the code seems to work fine.

Kelvin
kli
 
Posts: 6
Joined: Thu Jan 08, 2009 7:39 pm

Re: #pragma omp task

Postby Ranzeeta » Tue Jun 02, 2009 3:36 am

Hi Kelvin,

thanks for your reply but even i change srand (0.000001) to srand(123456), i am still getting the same value i.e 0 for the "second coagulated value(ipartner2)". I cannot figure it out my mistake. what would be the best solution to parallelize such "while" loop program??

greetings
Ranzeeta
 
Posts: 10
Joined: Wed Jan 07, 2009 6:56 am
Location: NRW , Germany

Re: #pragma omp task

Postby kli » Tue Jun 02, 2009 8:24 am

Apparently, the second while loop only executes once, so "ipartner2" acquires the value of zero from "j" in the first iteration.

In general, OpenMP task construct is good for parallelizing condition-controlled loops (such as while loops).

Kelvin
kli
 
Posts: 6
Joined: Thu Jan 08, 2009 7:39 pm

Re: #pragma omp task

Postby Ranzeeta » Wed Jul 01, 2009 9:56 am

thanks for your post for my previous problem.If anyone can help me regarding the following problem.

For example , i have a code structure

if (-----)
{
while ( value < rannum)
{
do something ;
if ( )
do something ;

while ( )
{
do something ;
}
}
}


lets say, I need to generate a value. it might be negative or positve.
is it possible to do it simultaneously the same job with the four processors in openMP ? My purpose is not to parallelize the code but to do the whole task simultaneously with all processors.
if its more than 1 positive values , then I have to choose any positive value from any of the processors as I need only one positive value and the negative value should be rejected.
If all the processors generate negative values then, calculation is done again till we get atleast 1 positive value.
hope its not that confusing.

with thanks
Ranzeeta
 
Posts: 10
Joined: Wed Jan 07, 2009 6:56 am
Location: NRW , Germany

Re: #pragma omp task

Postby Tommy » Thu Aug 13, 2009 5:13 am

It is very nice post.Thanks for sharing this.Thank you.
pass4sure is famous for help candicates pass IT exams for sure.
Tommy
 
Posts: 1
Joined: Thu Aug 13, 2009 5:10 am


Return to OpenMP 3.0 API Specifications

Who is online

Users browsing this forum: Google [Bot] and 1 guest