Synergy User Manual and Tutorial. - THE CORE MEMORY
Synergy User Manual and Tutorial. - THE CORE MEMORY
Synergy User Manual and Tutorial. - THE CORE MEMORY
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 />
Tuple Space Object Programming<br />
A Simple Application – Hello <strong>Synergy</strong>!<br />
The first example given in most introductory computer programming books is the “Hello<br />
World!” program. To get started with <strong>Synergy</strong> programming, the “Hello <strong>Synergy</strong>!”<br />
program will be the first example. The master program (tupleHello1Master.c) simply<br />
opens a tuple space, puts the message in the tuple space <strong>and</strong> terminates. The worker<br />
programs (tupleHello1Worker.c) open the tuple space, read the message from the tuple<br />
space, display the message <strong>and</strong> terminate. The following example programs can be found<br />
in the example01 directory.<br />
The following is the tuple space “Hello <strong>Synergy</strong>!” master program:<br />
#include <br />
#include <br />
main(){<br />
int tplength;<br />
int status;<br />
int P;<br />
int tsd;<br />
char host[128];<br />
char tpname[20];<br />
// Length of ts entry<br />
// Return status for tuple operations<br />
// Number of processors<br />
// Problem tuple space identifier<br />
// Host machine name<br />
// Identifier of ts entry<br />
// Message sent to workers<br />
char sendMsg[50] = "Hello <strong>Synergy</strong>!\0";<br />
// Get host machine name<br />
gethostname(host, sizeof(host));<br />
// Open tuple spaces<br />
printf("Master: Opening tuple space\n");<br />
// Open problem tuple space<br />
tsd = cnf_open("problem",0);<br />
printf("Master: Tuple space 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 />
131