[Omp] How to private an array ?
Kang Su Gatlin
kanggatl at microsoft.com
Sun Jun 19 11:14:29 PDT 2005
You could create an array of 'n' critical sections and take the ones you need for each loop iteration (of course taking them in some predetermined order to avoid deadlock). That's one way to do it in order to minimize sequentializing your application. With that said, having 1000s of critical sections is a lot. Never actually done that myself before. I can't say that what I'm suggesting is a good idea, but it is one way to do it.
And yes, Visual C++ 8.0 will have support for OpenMP. Currently we're in Beta (we will ship the final version Nov 7th), and the current Beta also does have support for OpenMP.
Thanks,
KSG
________________________________
From: Omp-bounces at openmp.org on behalf of ThanhVu Nguyen
Sent: Sat 6/18/2005 11:53 AM
To: omp at openmp.org
Subject: RE: [Omp] How to private an array ?
For example I want to share the array int shared1[2] (code below), I
can assigning each value index to a temp scalar value and apply
reduction on both of them. However I have to manually declare 2
temporary scalar values to to represent my array. Now if my array has
a large size (say 1000), how do I do something similar ? obviously I
don't want to declare manually 1000 temp scalar values.
int shared1[2] ; shared1[0]=100;shared1[1]=200;
shared2[0]=100; shared2[1]=200;
int temp0 = shared1[0]; int temp1 = shared1[1];
#pragma omp parallel for private(i) reduction(+:temp0,temp1)
for (i = 0 ; i < 1000 ; ++i){
if (i%3==0){ temp0--; }
else { temp1++; }
}
I see that your email address is from microsoft.com, do you know if
VSC++ supports openmp ? Thanks,
--- Kang Su Gatlin <kanggatl at microsoft.com> wrote:
> Could you give a snippet of the code that you're trying to
> parallelize
> with some description of what you'd like private/shared?
>
> Thanks,
>
> Kang Su Gatlin
> Visual C++ Program Manager
>
> -----Original Message-----
> From: Omp-bounces at openmp.org [mailto:Omp-bounces at openmp.org] On
> Behalf
> Of ThanhVu Nguyen
> Sent: Friday, June 17, 2005 10:39 PM
> To: omp at openmp.org
> Subject: [Omp] How to private an array ?
>
> Hi, I asked this question before but perhaps not clear enough so no
> reply. Here it is again: I need to share an array of data, I need to
> make sure that no thread can access this data at the same time
> otherwise will have race condition, so probably have to make it in
> critical section? Or I may be can create scalar values representing
> values of the array data and private them ... each threads will work
> on
> these values indepdently and at the end will synchronize, reduction
> etc
> on them. But I don't know the proper way to do that. If the array
> data
> has size n, then how to create n scalar values ?? What is the
> appropriate way to achieve my intention? Thanks in advance
>
>
>
>
> tvn,
>
> ThanhVu H. Nguyen
>
> _______________________________________________
> Omp mailing list
> Omp at openmp.org
> http://openmp.org/mailman/listinfo/omp_openmp.org
>
tvn,
ThanhVu H. Nguyen
_______________________________________________
Omp mailing list
Omp at openmp.org
http://openmp.org/mailman/listinfo/omp_openmp.org
More information about the Omp
mailing list