views:

33

answers:

0

Heres the problem..ill put what ive come up with at the bottom..but im a bit confused...im told to use forall statement..but we havent even learned that yet. So im trying to teach myself some..it seems like its a hard topic to find much on. The coding language is either called pidgin or Peril-L it says that they will define a pidgin programming language called Peril-L that can be used to analyze and develop parallel algorithms..I dont know looks like C++ really..

Rewrite the iterative summation program using forall; don't forget about race conditions? iterative summation program:

sum = 0;
for(i=0; i<n; i++)
{
sum+=[i];
}

Heres what part of the iterative solution for threads:

for(i=start; i<end; i++)
{
sum+=x[i];
}

I have no idea what it means by forall...not sure I have used a forall statement if thats what it wants?

I think it wants something similar to this?

int *x;
mutex m;
int i = 0;

int itersum()
{
forall(index in(0..i-1))
{
mutex_lock(m);
sum+=x[index];
i++;
mutex_unlock(m);
}
return sum;
}

Perhaps I wrote something wrong? But would there even be a race condition using a forall statement? I really just dont understand how the forall works..is there a race condition for the forall statement above?