MPIRoot.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2002 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 #ifndef __MPIRoot_h
10 #define __MPIRoot_h
11 
12 #include <mpi.h>
13 
14 #define ACTIVATE_MPI 1
15 #include "dsp/Input.h"
16 
17 
18 namespace dsp {
19 
21  class MPIRoot : public Input {
22 
23  public:
24 
25  friend class MPIServer;
26 
28  MPIRoot (MPI_Comm comm);
29 
31  virtual ~MPIRoot ();
32 
34  int get_size () const { return mpi_size; }
35 
37  int get_rank () const { return mpi_rank; }
38 
40  int get_root () const { return mpi_root; }
42  void set_root (int root);
43 
45  int get_tag () const { return mpi_tag; }
47  void set_tag (int tag) { mpi_tag = tag; }
48 
50  void set_block_size (uint64_t _size);
51 
53  void prepare ();
54 
56  bool eod();
57 
63 
65  void set_Input (Input* input);
66 
68  void serve (BitSeries* bitseries = 0);
69 
71 
73  void set_resolution (unsigned resolution);
74 
75  protected:
76 
78  virtual void set_eod(bool _eod){/* HSK doesn't know what to put here*/}
79 
81  void send_data (BitSeries* data, int dest);
82 
84  void load_data (BitSeries* data);
85 
87  void wait (MPI_Request& request, bool receive);
88 
90  int next_destination ();
91 
93  void size_pack_buffer ();
94 
96  MPI_Comm comm;
97 
99  int mpi_size;
100 
102  int mpi_rank;
103 
105  int mpi_root;
106 
108  int mpi_tag;
109 
112 
114  MPI_Request data_request;
115 
117  MPI_Request ready_request;
118 
120  MPI_Status status;
121 
123  int ready;
124 
126  char* pack_buf;
127 
130 
133 
136 
139 
142 
144  vector<bool> eod_sent;
145 
148 
150  void init();
151 
153  void request_ready ();
154 
156  void request_data ();
157 
159  int receive_data ();
160 
162  void load_data ();
163 
165  void ensure_root (const char* method) const;
166 
168  void ensure_receptive (const char* method) const;
169 
171  void check_error (int mpi_err, const char* call, const char* method);
172 
174  void check_status (MPI_Status& mpi_status, const char* method);
175 
177  void check_block_size (const char* method);
178 
179  };
180 
181 }
182 
183 
185 int mpiPack_size (const dsp::MPIRoot&, MPI_Comm comm, int* size);
186 
188 int mpiPack (const dsp::MPIRoot&, void* outbuf, int outcount,
189  int* position, MPI_Comm comm);
190 
192 int mpiUnpack (void* inbuf, int insize, int* position,
193  dsp::MPIRoot*, MPI_Comm comm);
194 
195 
196 #endif // !defined(__SeekInput_h)
void send_data(BitSeries *data, int dest)
Send the next block using MPI_Isend.
Definition: MPIRoot.C:361
MPI_Request ready_request
Handle to the asynchronous send/recv of ready flag.
Definition: MPIRoot.h:117
virtual void set_ndat(uint64_t _ndat)
Set the number of time samples in container.
Definition: Observation.h:105
int next_destination()
Returns the rank of the next node ready to receive data.
Definition: MPIRoot.C:318
void load_data()
when mpi_rank == mpi_root, load data from input
Definition: MPIRoot.C:345
unsigned get_resolution() const
Get the time sample resolution of the data source.
Definition: Input.h:125
int64_t get_input_sample(Input *input=0) const
Return the sample offset from the start of the data source.
Definition: BitSeries.C:138
unsigned resolution
Time sample resolution of the data source.
Definition: Input.h:178
void init()
initialize variables
virtual uint64_t get_nsamples(uint64_t nbytes) const
Return the number of samples in nbytes bytes.
Definition: Observation.C:548
char * pack_buf
Buffer used to store asynchronous send/recv.
Definition: MPIRoot.h:126
bool eod()
End of data.
Definition: MPIRoot.C:224
Pure virtual base class of all objects that can load BitSeries data.
Definition: Input.h:31
virtual uint64_t get_block_size() const
Return the number of time samples to load on each load_block.
Definition: Input.h:90
Contains all Baseband Data Reduction Library classes.
Definition: ASCIIObservation.h:17
int get_root() const
Get the rank of process sending data.
Definition: MPIRoot.h:40
virtual Observation * get_info()
Get the information about the data source.
Definition: Input.h:113
virtual unsigned char * get_rawptr()
Return pointer to the raw data buffer.
Definition: BitSeries.h:64
int min_header_size
MPI_Pack_size of the header in the buffer.
Definition: MPIRoot.h:135
Serves data from a number of MPIRoot instances.
Definition: MPIServer.h:24
void wait(MPI_Request &request, bool receive)
Wait for the MPI_Request to complete and check the MPI_Status.
Definition: MPIRoot.C:274
int receive_data()
wait for data to be received and return the data count
Definition: MPIRoot.C:470
void prepare()
Prepare for sending or receiving from root node.
Definition: MPIRoot.C:178
void request_data()
request data from the root
Definition: MPIRoot.C:442
int get_size() const
Get the number of nodes in communicator.
Definition: MPIRoot.h:34
int pack_size
Size actually needed.
Definition: MPIRoot.h:132
int pack_buf_size
Size of the above buffer.
Definition: MPIRoot.h:129
void set_block_size(uint64_t _size)
Setting the block_size requires resizing the buffer.
Definition: MPIRoot.C:156
uint64_t get_request_ndat() const
Number of time samples requested.
Definition: BitSeries.h:76
Loads BitSeries data using the MPI communications protocol.
Definition: MPIRoot.h:21
int mpi_rank
Rank of this process within the communicator.
Definition: MPIRoot.h:102
MPI_Status status
Status of the last call to wait.
Definition: MPIRoot.h:120
void set_tag(int tag)
Set the tag used for all communication.
Definition: MPIRoot.h:47
int mpi_size
Number of nodes in communicator.
Definition: MPIRoot.h:99
Stores information about digital, band-limited, time-varying signals.
Definition: Observation.h:33
void serve(BitSeries *bitseries=0)
Serve the data from Input.
Definition: MPIRoot.C:564
virtual uint64_t get_nbytes(uint64_t nsamples) const
Return the size in bytes of nsamples time samples.
Definition: Observation.C:543
virtual void set_eod(bool _eod)
Method that is p.v. in dsp::Input so that dsp::Seekable can set its 'end_of_data' flag....
Definition: MPIRoot.h:78
vector< bool > eod_sent
End of data has been sent to this node.
Definition: MPIRoot.h:144
void check_status(MPI_Status &mpi_status, const char *method)
verify that MPI_Wait returns as expected after MPI_Irecv
Definition: MPIRoot.C:301
void set_root(int root)
Set the rank of process sending data.
Definition: MPIRoot.C:133
bool auto_request
Automatically request the next data chunk.
Definition: MPIRoot.h:111
unsigned get_request_offset() const
Offset (owing to resolution) to the requested time sample.
Definition: BitSeries.h:73
virtual void set_start_time(MJD _start_time)
Set the start time of the leading edge of the first time sample.
Definition: Observation.h:150
int get_rank() const
Get the rank of this process within the communicator.
Definition: MPIRoot.h:37
virtual void seek(int64_t offset, int whence=0)
Seek to the specified time sample.
Definition: Input.C:282
void size_pack_buffer()
resize the pack_buf
Definition: MPIRoot.C:237
MPI_Request data_request
Handle to the asynchronous send/recv of data.
Definition: MPIRoot.h:114
A container for storing digitized (generally not floating point) data
Definition: BitSeries.h:35
void check_block_size(const char *method)
verify that the block_size is withing MPI size limits
Definition: MPIRoot.C:309
void check_error(int mpi_err, const char *call, const char *method)
throw an Error exception if mpi_err != MPI_SUCCESS
Definition: MPIRoot.C:291
int get_tag() const
Get the tag used for all communication.
Definition: MPIRoot.h:45
virtual ~MPIRoot()
Destructor.
Definition: MPIRoot.C:128
Reference::To< Input > input
The source from which input data will be read.
Definition: MPIRoot.h:147
void set_resolution(unsigned resolution)
Provide access to resolution attribute (required in mpiUnpack)
Definition: MPIRoot.C:151
int data_size
Size of the data in bytes.
Definition: MPIRoot.h:138
void ensure_receptive(const char *method) const
ensure that this instance is not the root and that eof = false
Definition: MPIRoot.C:621
void set_Input(Input *input)
Set the source from which input data will be read.
Definition: MPIRoot.C:142
void ensure_root(const char *method) const
ensure that this instance is the root and that mpi_size > 1
Definition: MPIRoot.C:611
int mpi_root
Rank of process sending data.
Definition: MPIRoot.h:105
int mpi_tag
Tag used for all communication.
Definition: MPIRoot.h:108
bool end_of_data
End of data.
Definition: MPIRoot.h:141
void change_start_time(int64_t _ndat)
Change the start time by the number of time samples specified.
Definition: Observation.C:514
MPIRoot(MPI_Comm comm)
Construct from MPI_Bcast.
Definition: MPIRoot.C:91
virtual void set_block_size(uint64_t _size)
Set the number of time samples to load on each load_block.
Definition: Input.C:399
int ready
The ready flag.
Definition: MPIRoot.h:123
MPI_Comm comm
Communicator in which data will be sent and received.
Definition: MPIRoot.h:96
void request_ready()
request ready-for-data from any node
Definition: MPIRoot.C:327

Generated using doxygen 1.8.17