Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallelization Issues #5

Open
Premas opened this issue Jul 5, 2017 · 2 comments
Open

Parallelization Issues #5

Premas opened this issue Jul 5, 2017 · 2 comments

Comments

@Premas
Copy link

Premas commented Jul 5, 2017

I tried to parallelize the below code using Par4all and I am able to get the parallelized code. But you can see that in the parallelized code, "n" is assigned with value 1410065407, instead of 1.0E10. Pls help me to solve the issue.

/** input code fragment **/

#define n 10000000000
for(i = 0 ; i < n ; i++)
A[i] = i;
for(i = 0 ; i < n ; i++)
sum += A[i];

/Parallelized code/
#pragma omp parallel for
for(i = 0; i <= 1410065407; i += 1)
A[i] = i;

#pragma omp parallel for reduction(+:sum)
for(i = 0; i <= 1410065407; i += 1)
sum += A[i];

@keryell
Copy link
Member

keryell commented Jul 5, 2017

10000000000-2^33
1410065408

OK, so this code by itself is not really portable since you guess you have at least 34-bit integers to store this constant...

Unfortunately PIPS assumes 32-bit integers, so this constant...
I hope there is a warning during compilation.

What about:

const long long int n = 10000000000LL;
for(i = 0 ; i < n ; i++)
A[i] = i;
for(i = 0 ; i < n ; i++)
sum += A[i];

?

@Premas
Copy link
Author

Premas commented Jul 6, 2017

Sorry for the delay. Thank you for your reply.
No, I didn't get any user warning related to memory.
Thank you, this method works. Instead of defining 'n' as a macro, I defined 'n' as variable and assigned '10000000000'. Now it works.

/*input code */
long long int n= 10000000000;
for(i = 0 ; i < n ; i++)
sum += A[i];

/*parallelized code */
long long int n= 10000000000;
#pragma omp parallel for reduction(+:sum)
for(i = 0; i <= n-1; i += 1)
sum += A[i];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants