| 1 |
#include <mpi.h> |
| 2 |
#include <music.hh> |
| 3 |
#include <fstream> |
| 4 |
#include <sstream> |
| 5 |
|
| 6 |
#define TIMESTEP 0.0005 |
| 7 |
|
| 8 |
MPI_Comm comm; |
| 9 |
double* data; |
| 10 |
|
| 11 |
int |
| 12 |
main (int args, char* argv[]) |
| 13 |
{ |
| 14 |
MUSIC::Setup* setup = new MUSIC::Setup (args, argv); |
| 15 |
|
| 16 |
MUSIC::ContInputPort* wavedata = |
| 17 |
setup->publishContInput ("wavedata"); |
| 18 |
|
| 19 |
comm = setup->communicator (); |
| 20 |
int nProcesses; |
| 21 |
MPI_Comm_size (comm, &nProcesses); // how many processes are there? |
| 22 |
int rank; |
| 23 |
MPI_Comm_rank (comm, &rank); // which process am I? |
| 24 |
int width = 0; |
| 25 |
if (wavedata->hasWidth ()) |
| 26 |
width = wavedata->width (); |
| 27 |
else |
| 28 |
MPI_Abort (comm, 1); |
| 29 |
|
| 30 |
// For clarity, assume that width is a multiple of n_processes |
| 31 |
int nLocalVars = width / nProcesses; |
| 32 |
data = new double[nLocalVars]; |
| 33 |
std::ostringstream filename; |
| 34 |
filename << argv[1] << rank << ".out"; |
| 35 |
std::ofstream file (filename.str ().data ()); |
| 36 |
|
| 37 |
// Declare where in memory to put data |
| 38 |
MUSIC::ArrayData dmap (data, |
| 39 |
MPI_DOUBLE, |
| 40 |
rank * nLocalVars, |
| 41 |
nLocalVars); |
| 42 |
wavedata->map (&dmap); |
| 43 |
|
| 44 |
double stoptime; |
| 45 |
setup->config ("stoptime", &stoptime); |
| 46 |
MUSIC::Runtime* runtime = new MUSIC::Runtime (setup, TIMESTEP); |
| 47 |
for (int j =0; runtime->time () < stoptime; j++) |
| 48 |
{ |
| 49 |
runtime->tick (); |
| 50 |
// Dump to file |
| 51 |
for (int i = 0; i < nLocalVars; ++i) |
| 52 |
file << data[i] << ' '; |
| 53 |
file << std::endl; |
| 54 |
|
| 55 |
} |
| 56 |
runtime->finalize (); |
| 57 |
|
| 58 |
delete runtime; |
| 59 |
|
| 60 |
return 0; |
| 61 |
} |