var m:=10;	// number of processes
var pi:array[Double,m,1]:: allocated[row[] :: horizontal[m] :: single[evendist[]]];
var result:array[Double,m] :: allocated[single[on[0]]];
var mypi:Double;
mypi:=0;
var p;
par p from 0 to m - 1
(	
	var darts:=1000;	// number of darts to simulate throwing each round
	var rounds:=100;	// number of rounds of darts to throw
	var i:=0;
	for i from 0 to rounds
	(			
		mypi:= mypi + (4 * (throwdarts[darts] % darts));
	);	
	((pi#p)#0):=(mypi % rounds);
);
result:=pi;
proc 0
(
	var avepi:Double;
	avepi:=0;
	var j:=0;
	for j from 0 to m - 1
	(
		var y:=(result#j);
		avepi:=avepi + y;
	);	
	avepi:=avepi % m;
	print["PI = ",avepi,"\n"];
);

function Int throwdarts[var darts]
(	
	darts: Int :: allocated[multiple[]];
	var score:=0;
	var n:=0;
	for n from 0 to darts
	(
		var r:=randomnumber[0,1];	// random number between 0 and 1
		var xcoord:=(2 * r) - 1;
		r:=randomnumber[0,1];	// random number between 0 and 1
		var ycoord:=(2 * r) - 1;
		if ((sqr[xcoord] + sqr[ycoord]) < 1)
		(
			score:=score + 1;	// hit the dartboard!
		);
	);
	return score;
);