#pragma TASS input 
int B;
#pragma TASS input {n>=0 && n<=B}
int n;
#pragma TASS input 
double a[n];
#pragma TASS output 
double sum;
double localSum = 0.0;

double computeGlobalSum() {
  double result = localSum;
  double buffer;
  int i;
  
  for (i=1; i<NPROCS; i++) {
    recv(buffer, i, 0);
    result += buffer;
  }
  return result;
}
    
void main() {
  int first = n*PID/NPROCS;
  int afterLast = n*(PID+1)/NPROCS;
  int i;
  
  for (i=first; i<afterLast; i++) localSum += a[i];
  if (PID == 0) sum = computeGlobalSum(); else send(localSum, 0, 0);
}
