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

Sending Various Data Types<br />

<strong>Synergy</strong> can put <strong>and</strong> get more than characters from its tuple space. The following<br />

example shows how to put various data types into a tuple space <strong>and</strong> get various data types<br />

out of a tuple space. The master program (tuplePassMaster.c) puts different data types<br />

into the problem tuple space, <strong>and</strong> the worker (tuplePassWorker.c) gets them, displays<br />

them <strong>and</strong> puts messages in the result tuple space identifying which data types it took.<br />

This application also uses a distributed semaphore to ensure that the workers take data<br />

properly. It also demonstrates the difference between the cnf_read() <strong>and</strong> cnf_get()<br />

functions. The tuplePass application is located in the example03 directory. The<br />

tuplePass.h file has the definitions for the constant <strong>and</strong> the data structure used in the<br />

application.<br />

The following is the tuple space “data type passing” master program:<br />

#include <br />

#include <br />

#include "tuplePass.h"<br />

main(){<br />

int tplength;<br />

int status;<br />

int P;<br />

int i;<br />

int res;<br />

int tsd;<br />

int sem;<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 />

// Semaphore<br />

// Host machine name<br />

// Identifier of ts entry<br />

// Message received from workers<br />

// Different datatypes to send to workers<br />

// Integer sent to worker<br />

int num = 12000;<br />

int *numPtr = &num;<br />

// Long integer sent to worker<br />

long lnum = 1000000;<br />

long *lnumPtr = &lnum;<br />

// Float sent to worker<br />

float frac = 0.5;<br />

float *fracPtr = &frac;<br />

// Double sent to worker<br />

double dfrac = 12345.678;<br />

double *dfracPtr = &dfrac;<br />

// Integer array sent to worker<br />

int numArr[MAX] = {0,1,2,3,4};<br />

140

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

Saved successfully!

Ooh no, something went wrong!