29.01.2015 Views

Dr. David Cronk Innovative Computing Lab University of ... - It works!

Dr. David Cronk Innovative Computing Lab University of ... - It works!

Dr. David Cronk Innovative Computing Lab University of ... - It works!

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Master/Slave Example<br />

Do some computation for each <strong>of</strong> N elements in a large array.<br />

The amount <strong>of</strong> computation depends on the value <strong>of</strong> each element.<br />

Main<br />

Call MPI_INIT (ierr)<br />

comm = MPI_COMM_WORLD<br />

Call MPI_COMM_RANK (comm, rank, ierr)<br />

Call MPI_COMM_SIZE (comm, size, ierr)<br />

stride = N/(10*(size-1))<br />

If (rank .eq. 0)<br />

call master ()<br />

Else<br />

call slave()<br />

Endif<br />

Call MPI_FINALIZE (ierr)<br />

<strong>David</strong> <strong>Cronk</strong> 48

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

Saved successfully!

Ooh no, something went wrong!