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

MPI_Finalize();<br />

which disables the MPI interface. To compile <strong>and</strong> run an MPI application type:<br />

[c615111@owin ~/mpi ]>mpicc -o hello hello.c<br />

[c615111@owin ~/mpi ]>mpirun –np 4 hello<br />

The mpirun comm<strong>and</strong> activates a MPI application named “hello” with 4 processes (1<br />

master <strong>and</strong> 3 workers) <strong>and</strong> the mpicc comm<strong>and</strong> is actually not a proprietary compiler. It<br />

is a definition that is equivalent a call to the cc compiler with the following arguments to<br />

access the proper libraries:<br />

[c615111@owin ~/mpi ]>cc -o hello hello.c -I/usr/local/mpi/include\<br />

-L/usr/local/mpi/lib -lmpi<br />

An example of an MPI application is:<br />

// hello.c program<br />

#include <br />

#include “mpi.h”<br />

main(int argc, char** argv){<br />

int my_rank;<br />

int p;<br />

int source;<br />

int dest;<br />

int tag = 50;<br />

char buf[100];<br />

MPI_Status status;<br />

FILE* fd;<br />

// Rank of process<br />

// Number of processes<br />

// Rank of sender in loops<br />

// Rank of receiver<br />

// Tag for messages<br />

// Storage buffer for the message<br />

// Return status for receive<br />

// File in which to write master’s message<br />

// Open file to store message<br />

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

// Get host machine name<br />

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

// Initialize MPI application session<br />

// No MPI functions may be used until this is called<br />

// This function may only be called once<br />

MPI_Init(&argc, &argv);<br />

// Get my rank<br />

// Master’s rank will be ‘0’<br />

// Worker’s ranks will be greater than ‘0’<br />

MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);<br />

// Get the number of running processes<br />

MPI_Comm_size(MPI_COMM_WORLD, &p);<br />

// If my_rank != 0, I am a worker<br />

74

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

Saved successfully!

Ooh no, something went wrong!