473,387 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Issue parallelizing this c code with openmp

How can I parallelize this code with OpenMP?. The result I get is not correct.

I try to use temporary variables p1aux, p2aux, and psumaux because the Reduction clause cannot be used with pointers or intrinsic functions. But as I said the result is incorrect.

When I say "result is not correct", I would say: The calculations of array1 + array2 are stored in the matrix sumsse. The calculations are correct until the component sumsse[50] [50] [50], more or less, but the other components of the matrix are always 0.

Do You have any idea what might happen?.

If anyone can help me, thank you very much.

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #ifdef __SSE2__
  3. #include <emmintrin.h>
  4. #endif
  5.  
  6. #include <omp.h>
  7. #include <stdlib.h>
  8. #include <math.h>
  9.  
  10. double __attribute__((aligned(16))) array1[256][256][256],array2[256][256][256];
  11. double __attribute__((aligned(16))) sumsse[256][256][256];
  12.  
  13.  
  14.  
  15. int main ()
  16. {
  17.  
  18.     int k,j,i,dim;
  19.     dim=256;
  20.  
  21.  
  22.     __m128d *p1= (__m128d*) &array1[0][0][0];
  23.     __m128d *p2= (__m128d*) &array2[0][0][0];
  24.     __m128d *psum= (__m128d*) &sumsse[0][0][0];
  25.  
  26.     __m128d *p1aux= (__m128d*) &array1[0][0][0];
  27.     __m128d *p2aux= (__m128d*) &array2[0][0][0];
  28.     __m128d *psumaux= (__m128d*) &sumsse[0][0][0];
  29.  
  30.     int nthreads =(8);
  31.     omp_set_num_threads(nthreads);
  32.  
  33.  
  34.     //initializa array2
  35.  
  36.     for(k = 0; k < dim; ++k){
  37.         for(j = 0; j < dim; ++j){
  38.             for(i = 0; i < dim; ++i){
  39.                 array2[k][j][i] = 1.0;
  40.             }
  41.         }
  42.     }
  43.  
  44.     //initialize array1
  45.  
  46.     for(k = 0; k < dim; ++k){
  47.         for(j = 0; j < dim; ++j){
  48.             for(i = 0; i < dim; ++i){
  49.                 array1[k][j][i] = i + j + k;
  50.             }
  51.         }
  52.     }
  53.  
  54.     //initialize array sumsse
  55.  
  56.     for(k = 0; k < dim; ++k){
  57.         for(j = 0; j < dim; ++j){
  58.             for(i = 0; i < dim; ++i){
  59.                 sumsse[k][j][i] = 0.0;
  60.             }
  61.         }
  62.     }
  63.  
  64.     //add array1 + array2 with sse 
  65.  
  66. #pragma omp parallel firstprivate(p1,p2,p1aux,p2aux)
  67.     {
  68.  
  69.     for(k = 0; k < dim; ++k){
  70.  
  71.         for(j = 0; j < dim; ++j){
  72.  
  73. #pragma omp for private(i)
  74.  
  75.                 for(i = 0; i < dim; i += 2){
  76.  
  77.                     *psum = _mm_add_pd(*p1,*p2);
  78.  
  79.                     psum = psumaux + 1;
  80.                     p1 = p1aux+1;
  81.                     p2 = p2aux+1;
  82.                     psumaux = psum;
  83.                     p1aux = p1;
  84.                     p2aux = p2;
  85.                 }
  86.             }
  87.         }
  88.  
  89.     }// end parallel
  90.  
  91.  
  92.     //show some datas
  93.  
  94.  
  95.     printf("Elementosse=10 sumsse=%f",sumsse[10][10][10]);
  96.     printf("\n");
  97.     printf("Elementosse=50 sumsse=%f",sumsse[50][50][50]);   
  98.     printf("Elementosse=100 sumsse=%f",sumsse[100][100][100]);
  99.     printf("\n");
  100.     printf("Elementosse=120 sumsse=%f",sumsse[120][120][120]);
  101.     printf("\n");
  102.     printf("Elementosse=200 sumsse=%f",sumsse[200][200][200]);
  103.     printf("\n");
  104.  
  105.     return 0;
  106. }
  107.  
Mar 26 '12 #1
0 1218

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Brian Piotrowski | last post by:
Hi All, I almost have the connection working for my connection to the AS/400 from an ASP page. However, I have an error appearing, and I'm not sure how to fix it. The code I have for...
0
by: Scott Svendsen | last post by:
I am using HtmlInputFile for users to upload files to the webserver. I have this application on 2 servers (machine A IIS5.1 on XP pro'; machine B IIS 6.0 win 2003 web server). I am banging my...
4
by: sengkok | last post by:
hi, i have written a small print job monitoring program which can monitor the job ID and total pages printed . i am facing on strange problem which is the total print pages is always equal to 1 ,...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
0
by: jbrag | last post by:
Hi My 2003 and XP web application server machines have a problem related to ASP.NET framework. The IIS/ASP.NET generates javascript code in my Xxx.ASPX pages containing this fragment : ...
135
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about...
5
by: golfer1212 | last post by:
I wrote this program and it seems to work but I have to hit the enter key twice before the else statement will execute. I have no idea what the problem is? Here is the code: #include...
1
by: impulsenine | last post by:
Hello all. I have yet another IE float drop challenge for you. I am aware that this comes up a lot, and I hope I'm not trying your patience by asking for help with it. The page has 3 columns,...
9
by: John007 | last post by:
I am using a SQLDataSource to populate my gridview in ASP.Net 2.0. When I hit Edit, the textboxes appear and I am able to edit my values. When I hit Update, the changes are not saved, and there is no...
1
by: koyanpaing | last post by:
Hello everyone, I have a problem with overlapping. Overlapping is only when the mp3 file is playing and drop down list from project info come down. How can i control that kind of issue. My code...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.