[Omp] How to private an array ?
Marina Kraeva
kraeva at iastate.edu
Tue Jun 21 08:29:37 PDT 2005
ThanhVu,
I believe Larry meant something like this:
int shared1[2] ; shared1[0]=100;shared1[1]=200;
#pragma omp parallel private(pshared1)
{
#pragma omp for private(i)
for (i = 0 ; i < 1000 ; ++i){
if (i%3==0){ pshared1[0]--; }
else { pshared1[1]++; }
}
#pragma omp critical (sumshared1)
{
for (j=0; j<1; j++) {
shared1[j]+=pshared1[j];
}
}
}
Marina.
ThanhVu Nguyen wrote:
> Hi, what's the meaning of private arrays ? did you mean instead of do
> reduction on arrayV[2] then I should split it to temp0=arrayV[0] and
> temp1=arrayV[1] then reduction(temp0,temp1) ? Unfortunately I have not
> yet considering converting my current code to Fortran, Thanks.
>
>
>
> --- "Meadows, Lawrence F" <lawrence.f.meadows at intel.com> wrote:
>
>
>>You can't do array reductions in C/C++. You could do it
>>by hand with private arrays, then sum them all together
>>in a critical section or possibly with a more clever
>>algorithm. Or, you could use Fortran. Adding array reductions
>>to C/C++ is under consideration.
>>
>>Regards,
>>
>>Larry Meadows
>>
>>
>>>-----Original Message-----
>>>From: Omp-bounces at openmp.org [mailto:Omp-bounces at openmp.org]
>>>On Behalf Of ThanhVu Nguyen
>>>Sent: Saturday, June 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
>>>
>>
>
>
> 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