Sierra Toolkit  Version of the Day
mpih.hpp
Go to the documentation of this file.
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2002, 2009 Sandia Corporation. */
3 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
4 /* non-exclusive license for use of this work by or on behalf */
5 /* of the U.S. Government. Export of this program may require */
6 /* a license from the United States Government. */
7 /*--------------------------------------------------------------------*/
18 #ifndef STK_UTIL_PARALLEL_mpih_h
19 #define STK_UTIL_PARALLEL_mpih_h
20 
21 #include <vector>
22 #include <mpi.h>
23 
25 
26 #include <MPIH_Include.h>
27 
28 namespace sierra {
29 namespace mpih {
30 
39 void Enable();
40 
41 void Keyval_delete(MPI_Comm comm);
42 
57 void Sub_Communicator (MPI_Comm old_comm,
58  MPI_Comm new_comm);
59 
66 void Register_Handles ();
67 
78 void Add_Handle (const ExParallel &X);
79 
85 void Delete_Handles ();
86 
99 void Bcast(void * buffer,
100  int count,
101  MPI_Datatype datatype,
102  int root);
103 
104 void Allreduce( void * in_buffer,
105  void * out_buffer,
106  int count,
107  MPI_Datatype datatype,
108  MPI_Op op );
109 
110 void Gather( void * send_buf,
111  int send_size,
112  MPI_Datatype send_datatype,
113  void * recv_buf,
114  int recv_size,
115  MPI_Datatype recv_datatype,
116  int root);
117 
118 void Reduce( void * in_buffer,
119  void * out_buffer,
120  int count,
121  MPI_Datatype datatype,
122  MPI_Op op,
123  int root);
124 
125 void Reduce_Scatter( void * in_buffer,
126  void * out_buffer,
127  int recv_count,
128  MPI_Datatype datatype,
129  MPI_Op op);
130 
131 void Scatter( void * send_buf,
132  int send_size,
133  MPI_Datatype send_datatype,
134  void * recv_buf,
135  int recv_size,
136  MPI_Datatype recv_datatype,
137  int root);
138 
139 void Map_Free(MPIH_Map * map);
140 
141 void Map_Query
142 (MPIH_Map map /* in: Map for the sparse operation */,
143  int *symmetric /* out: */,
144  size_t *nsend /* out: Number of sends */,
145  std::vector<int> *sendlist /* out: List of destinations */,
146  std::vector<int> *sendlength /* out: */,
147  std::vector<int> *sendbuflen /* out: */,
148  size_t *nrecv /* out: Number of receives */,
149  std::vector<int> *recvlist /* out: List of destinations */,
150  std::vector<int> *recvlength /* out: */,
151  std::vector<int> *recvbuflen /* out: */ );
152 
153 void Sparse
154 (void * sendbuf /* in: address of send buffer */ ,
155  MPI_Datatype sendtype /* in: datatype of the send messages */ ,
156  void * recvbuf /* in: address of receive buffer */ ,
157  MPI_Datatype recvtype /* in: datatype of the recv messages */ ,
158  int transpose /* in: whether to reverse communic. */ ,
159  MPIH_Map map /* in: communication map */ );
160 
161 /* The Sparse is a combination of Initialize_Sparse and Wait_Sparse.
162  * This allows computation to happen while the communication is
163  * begin processed. After the call to Initialize_Sparse the
164  * buffers should NOT be reused until the completion of the
165  * corresponding Wait_Sparse call. The map passed to Wait_Sparse
166  * must be the same map that was used in Initialize_Sparse.
167  * Also, it is not possible to call Initialize_Sparse twice followed
168  * by two calls to Wait_Sparse. Because MPI does not guarentee
169  * the order that messages are received, the first Wait_Sparse
170  * could get the messages from the second Initialize_Sparse.
171  */
172 void Initialize_Sparse
173 (void * sendbuf /* in: address of send buffer */ ,
174  MPI_Datatype sendtype /* in: datatype of the send messages */ ,
175  void * recvbuf /* in: address of receive buffer */ ,
176  MPI_Datatype recvtype /* in: datatype of the recv messages */ ,
177  int transpose /* in: whether to reverse communic. */ ,
178  MPIH_Map map /* in: communication map */ );
179 
180 void Wait_Sparse
181 (MPIH_Map map /* in: communication map */ );
182 
183 void Sparse_Map
184 (const std::vector<int> &lengths /* in: Byte length of each message */ ,
185  const std::vector<int> &buflens /* in: Byte length of each message buffer */ ,
186  const std::vector<int> &sendlist /* in: Destination processors */ ,
187  MPIH_Map * map /* out: Map for the sparse operation */ );
188 
189 void Sparse_Symmetric_Map
190 (const std::vector<int> &lengths /* in: Length of each message */ ,
191  const std::vector<int> &buflens /* in: Length of each message buffe */ ,
192  const std::vector<int> &sendlist /* in: Destination processors */ ,
193  MPIH_Map * map /* out: Map for the sparse operation */ );
194 
195 inline void ParallelExceptionCheck()
196 {
197  int dummy = 0;
198  Bcast(&dummy, 0, MPI_INT, 0);
199 }
200 
201 
202 /*
203  * The rest of the functions are unlikely to be used
204  * outside of mpih.C.
205  */
206 
207 /* Local handle, Global handles, and just plain handles:
208  *
209  * Just plain handles are the handles that are registered
210  * on this processor. The number of them is unknown
211  * in advance. These are required to be consistant
212  * across all processors.
213  *
214  * local_handle is singular, it refers to the exception
215  * handle that has been set on the local processor.
216  * This is the handle that will be propagated on
217  * the next collective communication.
218  *
219  * Global handles is the collection of local handles
220  * from all of the processors after the collective
221  * communication. There will be one for each
222  * processor, but some will be NULL if there was not
223  * a local handle set for that processor.
224  */
225 void Activate_Handles ();
226 void Deactivate_Handles ();
227 int Get_Nhandles ();
228 void Get_Handles (ExParallel **handles);
229 
230 ExParallel *Get_Local_Handle ();
231 void Set_Local_Handle (ExParallel &handle);
232 void Reset_Local_Handle ();
233 
234 void Get_Global_Handles (ExParallel ** handles);
235 int Get_Global_Status ();
236 
237 void Set_Status_Check ();
238 void Reset_Status_Check ();
239 int Get_Status_Check ();
240 
241 void Get_Tags (int *active,
242  int *tag_sparse,
243  int *tag_normal,
244  int *tag_message);
245 
246 void Get_Functions (MPIH_Handler_compete *handler_compete_fn ,
247  MPIH_Handler_execute *handler_execute_fn );
248 
249 int Get_Control_Message();
250 
251 /* interface for the product versioning. */
252 const char *get_product_name();
253 const char *get_product_version();
254 const char *get_product_qualifier();
255 void register_product();
256 
257 } // namespace mpih
258 } // namespace sierra
259 
260 #endif // STK_UTIL_PARALLEL_mpih_h
Definition: Env.cpp:53
void Register_Handles()
Member function Register_Handles is called during creation of this singleton. All of the exception su...
void Enable()
Member function Enable initializes exception handling.
void Bcast(void *buffer, int count, MPI_Datatype datatype, int root)
void Delete_Handles()
Member function Delete_Handles deletes all exception handles. Should only be called in destructor...
void Sub_Communicator(MPI_Comm old_comm, MPI_Comm new_comm)
Member function Sub_Communicator initialize a new communicator from an old one. This is an unusual ca...
void Add_Handle(const ExParallel &X)
Member function Add_Handle additional exceptions can be added with Add_Handle. This would be neccessa...