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

Sending <strong>and</strong> Receiving Data<br />

Hello Workers!—Hello Master!!!<br />

In this example application, the master (tupleHello2Master.c) sends the message “Hello<br />

Workers!” to all workers (tupleHello2Worker.c) <strong>and</strong> gets the response “Hello Master!!!”<br />

<strong>and</strong> the worker’s name from each worker. The source code, makefile <strong>and</strong> csl file for this<br />

application is located in the example02 directory.<br />

The following is the tuple space “Hello Workers!—Hello Master!!!” master program:<br />

#include <br />

#include <br />

main() {<br />

int tplength;<br />

int status;<br />

int P;<br />

int i;<br />

int res;<br />

int tsd;<br />

char host[128];<br />

char tpname[20];<br />

char recdMsg[50];<br />

// Length of ts entry<br />

// Return status for tuple operations<br />

// Number of processors<br />

// Counter index<br />

// Result tuple space identifier<br />

// Problem tuple space identifier<br />

// Host machine name<br />

// Identifier of ts entry<br />

// Message received from workers<br />

// Message sent to workers<br />

char sendMsg[50] = "Hello Workers!\0";<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 />

// Send 'Hello <strong>Synergy</strong>!' to problem tuple space<br />

// Set length of send entry<br />

tplength = sizeof(sendMsg);<br />

// Set name of entry to host<br />

strcpy(tpname, host);<br />

printf("Master: Putting '%s' Length %d Name %s\n",<br />

sendMsg, tplength, tpname);<br />

// Put entry in tuple space<br />

136

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

Saved successfully!

Ooh no, something went wrong!