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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

Work Distribution by Chunking<br />

Finding the Sum of the First n Integers with Chunking<br />

The following is the tuple space “sum of n integers” master program implemented by<br />

sending work in chunks:<br />

#include <br />

#include <br />

#define N 32<br />

main(){<br />

int P;<br />

// Number of processors<br />

int chunk_size;<br />

// Chunk size<br />

int remainder;<br />

// Remainder of numbers to be sent<br />

int i;<br />

// Counter index<br />

int job;<br />

// Job number<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 *sendArr = 0;<br />

// Number sent to problem ts<br />

int sendNum;<br />

// Number sent to worker in sendArr<br />

int recdSum = 0;<br />

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

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("Master: 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("Master: Tuple spaces open complete\n");<br />

// Get number of processors<br />

P = cnf_getP();<br />

printf("Master: Processors %d\n", P);<br />

// Get chunk size<br />

chunk_size = cnf_getf();<br />

printf("Master: Chunk size %d\n", chunk_size);<br />

// Put chunk size in ts<br />

// Set length of entry<br />

166

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

Saved successfully!

Ooh no, something went wrong!