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