1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include "message.h"
#include "maklib.h"

int main()
{
	int i, j, suma, sumaMax;

	suma = 0;
	sumaMax = 0;
	
	for(i=MyNodeId()+1; i<=Size(); i += NumberOfNodes())
	{
		for(suma=0,j=i; j<=Size(); ++j)
			{
				suma += ElementAt(j);
				if(suma > sumaMax) sumaMax = suma;
			}
	}

if (MyNodeId() > 0) 
  {
    PutInt(0, sumaMax);
    Send(0);
  } 

else 
{
    for (i = 1; i < NumberOfNodes(); ++i) 
	{
      Receive(i);
      suma = GetInt(i);
      if(suma > sumaMax) sumaMax = suma;
    }
    printf("%d\n",sumaMax);
  }	
	return 0;
}