openMp output

General OpenMP discussion

openMp output

Postby nguaze » Thu Aug 01, 2013 2:37 am

Hello Guys,
I need your Help to Understand -
I write Programm that use two Thread for Computation using openMP. The Size of my shared Buffer is 20 and each core need to work on 10 Element on the shared Buffer
void main()
{

float Buffer[ELEMENTS_to_SORTED * NUMBER_of_LINES]; // 20
float private_buffer[NUMBER_of_Lines_pro_Thread * ELEMENTS_to_SORTED]; // 10
int i, j, tid , x;

/* Initializations */
for (i=0; i < (ELEMENTS_to_SORTED * NUMBER_of_LINES); i++)
{
Buffer[i] = i * 1.0;
}
printf("\nStarting values inside the shared buffer:\n");
for (i=0; i < (ELEMENTS_to_SORTED * NUMBER_of_LINES); i++)
{
printf(" Buffer[%d]= %.1f",i ,Buffer[i]);
}
printf("\n compute shared data by thread:\n");

/* Create a team of threads and scope variables */
#pragma omp parallel shared(Buffer) private(tid,i,private_buffer)
{
tid = omp_get_thread_num();

/* Loop work-sharing construct - distribute rows of matrix */
#pragma omp for private(j) // each Thread work on 10 ELemente
for (i=0; i < NUMBER_of_LINES; i++)
{
for (j=0; j < (NUMBER_of_Lines_pro_Thread*ELEMENTS_to_SORTED); j++)
private_buffer[j] = Buffer[tid * NUMBER_of_Lines_pro_Thread*ELEMENTS_to_SORTED+j];
#pragma omp critical
{
/* print the private buffer for each Thread */
printf(" thread %d work \n",tid);
for (x =0 ; i<NUMBER_of_Lines_pro_Thread*ELEMENTS_to_SORTED; i++){
printf("%.1f ", private_buffer[i]);
}
}
}
return 0;
}
when I run this code I get the following Output : Buffer[0]= 0.0 Buffer[1]= 1.0 Buffer[2]= 2.0 Buffer[3]= 3.0 Buffer[4]= 4.0 Buffer[5]= 5.0 Buffer[6]= 6.0 Buffer[7]= 7.0 Buffer[8]= 8.0 Buffer[9]= 9.0 Buffer[10]= 10.0 Buffer[11]= 11.0 Buffer[12]= 12.0 Buffer[13]= 13.0 Buffer[14]= 14.0 Buffer[15]= 15.0 Buffer[16]= 16.0 Buffer[17]= 17.0 Buffer[18]= 18.0 Buffer[19]= 19.0
compute shared data by thread:
[C66xx_1] thread 1 work
11.0 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0
[C66xx_0] thread 0 work
0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0
At this point the programm work fine .

When I call a function with the parameter private_buffer , e.g : addelements(private_buffer) inside the omp critical and after the output
#pragma omp critical
{
/* print the private buffer for each Thread */
printf(" thread %d work \n",tid);
for (x =0 ; i<NUMBER_of_Lines_pro_Thread*ELEMENTS_to_SORTED; i++){
printf("%.1f ", private_buffer[i]);
}
addelements(private_buffer)
}
the contain of private_buffer still 0
[C66xx_1] thread 1 work
11.0 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0
0000000000 inside Add Element function()
[C66xx_0] thread 0 work
0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 inside Add Element
0000000000 inside Add Element function()
why the contains of private_buffer become 0 ?

Thank you for Reply
Lopez
nguaze
 
Posts: 4
Joined: Thu Jul 25, 2013 1:48 am

Re: openMp output

Postby MarkB » Thu Aug 01, 2013 2:52 am

Hi Lopez,

Are you sure you are formatting the output correctly inside addelements()?
Please can you post the source code for the addelements() function (and please could you use [code][/code] tags to make the code easier to read ;) )

Mark.
MarkB
 
Posts: 408
Joined: Thu Jan 08, 2009 10:12 am

Re: openMp output

Postby nguaze » Thu Aug 01, 2013 5:38 am

Hey Mark ,
you right :) , My formatting was incorrect : printf("%i", private_buffer[i]) , but the elements inside the private_buffer are float data.
:P Thank you Mark

Lopez
nguaze
 
Posts: 4
Joined: Thu Jul 25, 2013 1:48 am

Re: openMp output

Postby MarkB » Thu Aug 01, 2013 7:10 am

You're welcome!
MarkB
 
Posts: 408
Joined: Thu Jan 08, 2009 10:12 am


Return to Using OpenMP

Who is online

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