28.10.2014 Views

Synergy User Manual and Tutorial. - THE CORE MEMORY

Synergy User Manual and Tutorial. - THE CORE MEMORY

Synergy User Manual and Tutorial. - THE CORE MEMORY

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Synergy</strong> <strong>User</strong> <strong>Manual</strong> <strong>and</strong> <strong>Tutorial</strong><br />

Getting Workers to Work<br />

Sum of First N Integers<br />

The calculation of the sum of the first n integers or ∑i<br />

can be easily calculated in a<br />

regular computer program. An ANSI C program would be:<br />

#include <br />

#define N 6<br />

int main{<br />

int i;<br />

int sum = 0;<br />

}<br />

for(i=N; i>=N; i--)<br />

sum+=i;<br />

printf(“The sum of the first %d integers is %d\n”, N, sum);<br />

return 0;<br />

This problem can easily be performed in a parallel program by having the master<br />

(tupleSum1Master.c) put each integer into the problem tuple space. The workers<br />

(tupleSum1Workers.c) take the integers out of the problem tuple space, tally their<br />

respective sub sums <strong>and</strong> put the sub sums into the result tuple space. The master gets the<br />

sub sums from the result tuple space <strong>and</strong> produces the desires sum. This application is<br />

located in the example04 directory.<br />

The following is the tuple space sum of n integers master program:<br />

n<br />

i=<br />

1<br />

#include <br />

#include <br />

main(){<br />

int P;<br />

// Number of processors<br />

int i;<br />

// Counter index<br />

int status;<br />

// Return status for tuple operations<br />

int res;<br />

// Result tuple space identifier<br />

int tsd;<br />

// Problem tuple space identifier<br />

int maxNum = 6;<br />

// MAX of n for sum of 1..n<br />

int sendNum = 0;<br />

// Number sent to problem ts<br />

int *sendPtr = &sendNum; // Pointer to sendNum<br />

int recdSum = 0;<br />

// Subsum received from result ts<br />

int *recdPtr = &recdSum; // Pointer to recdSum<br />

int calcSum = 0;<br />

// Calculated sum<br />

int sumTotal = 0;<br />

// Sum total of all subsums<br />

int tplength;<br />

// Length of ts entry<br />

152

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!