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

// Transfer the message to PVM storage<br />

pvm_pkstr(buf);<br />

// Send the message signal to all workers<br />

for(i=0; i< NUM_WKRS; i++)<br />

pvm_send(tid[i], msgtag);<br />

// Print messages sent to workers<br />

printf(“Master: Messages sent to %d workers\n”)<br />

// Get replies from workers<br />

for(i=0; i< NUM_WKRS; i++){<br />

}<br />

// Execute a blocking receive to wait for reply from any (-1) worker<br />

pvm_recv(-1, msgtag);<br />

// Put the received message in the buffer<br />

pvm_upkstr(buf);<br />

// Print the message<br />

printf("Master: From %x: %s\n", tid, buf);<br />

// Print end message<br />

printf(“Master: Application is finished\n”);<br />

}<br />

}<br />

// Else the spawn was not successful<br />

else<br />

printf("Cannot start worker program\n");<br />

// Exit application<br />

pvm_exit();<br />

The master program spawns a number of workers, sends the “Hello worker…” message<br />

<strong>and</strong> waits for a reply. After the reply is received, it is printed to screen <strong>and</strong> the master<br />

terminates. The worker program is:<br />

// worker.c: “Hello Master” program<br />

#include <br />

main(){<br />

int ptid; // Parents task ID<br />

int msgtag; // Message tag to ID a message<br />

char buf[100]; // Message string buffer<br />

char host[128]; // Host machine name<br />

FILE* fd; // File in which to write master’s message<br />

// Open file to store message<br />

fd = fopen(“msg.txt”, "a");<br />

70

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

Saved successfully!

Ooh no, something went wrong!