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 />

}<br />

tplength = cnf_tsget(res, tpname, (char *)recdPtr, 0);<br />

printf("Master: Received %d from %s\n", recdSum, tpname);<br />

// Add result to total<br />

sumTotal += recdSum;<br />

// Increment counter<br />

i++;<br />

}<br />

printf("Master: The sum total is: %d\n", sumTotal);<br />

// Calculate correct answer with math formula<br />

calcSum = (maxNum*(maxNum+1))/2;<br />

printf ("Master: The calculated sum is: %d\n", calcSum);<br />

// Compare results<br />

if(calcSum == sumTotal)<br />

printf("Master: The workers gave the correct answer\n");<br />

else<br />

printf("Master: The workers gave an incorrect answer\n");<br />

// Terminate program<br />

printf("Master: Terminated\n");<br />

cnf_term();<br />

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

#include <br />

#include <br />

main(){<br />

// Variable declarations<br />

int tsd;<br />

// Problem tuple space identifier<br />

int res;<br />

// Result tuple space identifier<br />

int recdNum = 0;<br />

// Number received to be added<br />

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

int sendSum = 0;<br />

// Sum of numbers received<br />

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

int status;<br />

// Return status for tuple operations<br />

int tplength;<br />

// Length of ts entry<br />

char tpname[20];<br />

// Identifier of ts entry<br />

char host[128];<br />

// Host machine name<br />

// Get host machine name<br />

gethostname(host, sizeof(host));<br />

// Open tuple spaces<br />

printf("Worker: Opening tuple spaces\n");<br />

// Open problem tuple space<br />

tsd = cnf_open("problem", 0);<br />

// Open result tuple space<br />

res = cnf_open("result", 0);<br />

printf("Worker: Tuple spaces open complete\n");<br />

// Loop forever to accumulate sendSum<br />

154

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

Saved successfully!

Ooh no, something went wrong!