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

Optimized Programs<br />

Optimized Matrix Multiplication with Chunking<br />

The following is the tuple space “optimized matrix multiplication” master program<br />

implemented by sending work in chunks:<br />

#include <br />

#include <br />

#include <br />

// The A matrix to break up into arrays<br />

// <strong>and</strong> send to workers<br />

double A[N][N];<br />

double B[N][N];<br />

double C[N][N];<br />

#include "matrix.h"<br />

// Main function<br />

main(){<br />

int processors; // Number of processors<br />

int chunk_size; // Chunk size<br />

int remaining; // Remaining arrays of work<br />

int i, j;<br />

// Matrix indices<br />

int matrix_row; // Index of matrix row<br />

int array_pos; // Array position in rows array<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 />

double *rows; // Rows from A to send to worker<br />

double worker_time; // Sum of times returned by workers<br />

double total_time; // Total application run time<br />

int tplength; // Length of ts entry<br />

char tpname[20]; // Identifier of ts entry<br />

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

// Get host machine name<br />

gethostname(host, sizeof(host));<br />

// Get time stamp<br />

total_time = wall_clock();<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 />

185

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

Saved successfully!

Ooh no, something went wrong!