Datasharing Problem

General OpenMP discussion

Re: Datasharing Problem

Postby ftinetti » Wed Jan 22, 2014 6:15 am

Hi Yazan,

Please use code tags for the code.

Fernando.
ftinetti
 
Posts: 571
Joined: Wed Feb 10, 2010 2:44 pm

Re: Datasharing Problem

Postby yazan » Wed Jan 22, 2014 6:04 pm

thank you
Attachments
01.txt.tar.gz
(1.48 KiB) Downloaded 223 times
Last edited by yazan on Mon Apr 07, 2014 7:09 am, edited 1 time in total.
yazan
 
Posts: 7
Joined: Mon Jan 06, 2014 11:57 am

Re: Datasharing Problem

Postby MarkB » Thu Jan 23, 2014 4:46 am

Hi there,

I'm sorry: I made a mistake in my earlier suggestions. Making result private or firstprivate does not have the desired effect since each thread gets a private copy of the pointer but the storage it points to is still shared. One way around this is to create explicit private copies inside the parallel region, see below. I've given this a test, and it seems to work OK.

Apologies again,
Mark.

Code: Select all
   
#pragma omp parallel shared(result,indexx,matrix)
    {
       WORD* myresult = new WORD [intRows];
       while(indexx[0] <= n-(w-p)){
           #pragma omp for
           for(int i= indexx[w-p-1]; i<n; i++){
               for(int x=0; x<intRows; x++)
                   myresult[x] = result[x] ^ matrix[i][x];
               if(HW(myresult) == (WORD)p){
                    gettimeofday(&ende, NULL);
                    seconds = ende.tv_sec - start.tv_sec;
                    useconds = ende.tv_usec - start.tv_usec;
                    mtime = ((seconds)* 1000 +useconds/1000.5) +0.5;
                    cout << "\n\t\tTime: "<<mtime<<" milliseconds\n";
                   cout <<"\t *************************************** \t\n";
                   cout <<"\t *    !!!  SUCCESSFULLY   !!!          *\n";
                   cout <<"\t *************************************** \t\n";
                   cout <<"\t\t     ThreadID: "<<omp_get_thread_num()<<endl;
                   exit(EXIT_SUCCESS);
               }
           }
           #pragma omp master
           {
               if(indexx[0] <= n-(w-p)){
                   step = 1;
                   for(int i=w-p-2; i>=0; i--){
                       for(int x=0; x<intRows; x++)
                           result[x] ^= matrix[indexx[i]][x];
                       step++;
                       if(indexx[i] != n-step) // erreicht indexx[i] das maximum?
                           break;
                   }
                   indexx[w-p-step]++;
                   for(int x=0; x<intRows; x++)                   
                       result[x] ^= matrix[indexx[w-p-step]][x];
                   for(int i=w-p-step+1,offset=1; i<w-p; i++,offset++){
                       indexx[i]=indexx[w-p-step]+offset;
                       if(i!= w-p-1)                         
                           for(int x=0; x<intRows; x++)
                              result[x] ^= matrix[indexx[i]][x];
                   }
               }
           }
      #pragma omp barrier
       }
    }
MarkB
 
Posts: 427
Joined: Thu Jan 08, 2009 10:12 am

Re: Datasharing Problem

Postby yazan » Thu Jan 23, 2014 5:37 am

thank you very very much Mark, it works
yazan
 
Posts: 7
Joined: Mon Jan 06, 2014 11:57 am

Previous

Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 4 guests