1 // -*- c++ -*-
2 //
3 // Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
4 //                         University Research and Technology
5 //                         Corporation.  All rights reserved.
6 // Copyright (c) 2004-2005 The University of Tennessee and The University
7 //                         of Tennessee Research Foundation.  All rights
8 //                         reserved.
9 // Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10 //                         University of Stuttgart.  All rights reserved.
11 // Copyright (c) 2004-2005 The Regents of the University of California.
12 //                         All rights reserved.
13 // Copyright (c) 2008      Cisco Systems, Inc.  All rights reserved.
14 // Copyright (c) 2011      FUJITSU LIMITED.  All rights reserved.
15 // $COPYRIGHT$
16 //
17 // Additional copyrights may follow
18 //
19 // $HEADER$
20 //
21 
22 #include <string.h>
23 
24 //
25 // Point-to-Point Communication
26 //
27 
28 inline void
Attach_buffer(void * buffer,int size)29 MPI::Attach_buffer(void* buffer, int size)
30 {
31   (void)MPI_Buffer_attach(buffer, size);
32 }
33 
34 inline int
Detach_buffer(void * & buffer)35 MPI::Detach_buffer(void*& buffer)
36 {
37   int size;
38   (void)MPI_Buffer_detach(&buffer, &size);
39   return size;
40 }
41 
42 //
43 // Process Topologies
44 //
45 
46 inline void
Compute_dims(int nnodes,int ndims,int dims[])47 MPI::Compute_dims(int nnodes, int ndims, int dims[])
48 {
49   (void)MPI_Dims_create(nnodes, ndims, dims);
50 }
51 
52 
53 //
54 // Environmental Inquiry
55 //
56 
57 inline int
Add_error_class()58 MPI::Add_error_class()
59 {
60     int errcls;
61     (void)MPI_Add_error_class(&errcls);
62     return errcls;
63 }
64 
65 inline int
Add_error_code(int errorclass)66 MPI::Add_error_code(int errorclass)
67 {
68     int errcode;
69     (void)MPI_Add_error_code(errorclass, &errcode);
70     return errcode;
71 }
72 
73 inline void
Add_error_string(int errorcode,const char * string)74 MPI::Add_error_string(int errorcode, const char* string)
75 {
76     (void)MPI_Add_error_string(errorcode, const_cast<char *>(string));
77 }
78 
79 inline void
Get_processor_name(char * name,int & resultlen)80 MPI::Get_processor_name(char* name, int& resultlen)
81 {
82   (void)MPI_Get_processor_name(name, &resultlen);
83 }
84 
85 inline void
Get_error_string(int errorcode,char * string,int & resultlen)86 MPI::Get_error_string(int errorcode, char* string, int& resultlen)
87 {
88   (void)MPI_Error_string(errorcode, string, &resultlen);
89 }
90 
91 inline int
Get_error_class(int errorcode)92 MPI::Get_error_class(int errorcode)
93 {
94   int errorclass;
95   (void)MPI_Error_class(errorcode, &errorclass);
96   return errorclass;
97 }
98 
99 inline double
Wtime()100 MPI::Wtime()
101 {
102   return (MPI_Wtime());
103 }
104 
105 inline double
Wtick()106 MPI::Wtick()
107 {
108   return (MPI_Wtick());
109 }
110 
111 inline void
Real_init()112 MPI::Real_init()
113 {
114     MPI::InitializeIntercepts();
115 }
116 
117 
118 inline void
Init(int & argc,char ** & argv)119 MPI::Init(int& argc, char**& argv)
120 {
121   (void)MPI_Init(&argc, &argv);
122   Real_init();
123 }
124 
125 inline void
Init()126 MPI::Init()
127 {
128   (void)MPI_Init(0, 0);
129   Real_init();
130 }
131 
132 inline void
Finalize()133 MPI::Finalize()
134 {
135   (void)MPI_Finalize();
136 }
137 
138 inline bool
Is_initialized()139 MPI::Is_initialized()
140 {
141   int t;
142   (void)MPI_Initialized(&t);
143   return OPAL_INT_TO_BOOL(t);
144 }
145 
146 inline bool
Is_finalized()147 MPI::Is_finalized()
148 {
149   int t;
150   (void)MPI_Finalized(&t);
151   return OPAL_INT_TO_BOOL(t);
152 }
153 
154 
155 //
156 // External Interfaces
157 //
158 
159 inline int
Init_thread(int required)160 MPI::Init_thread(int required)
161 {
162   int provided;
163   (void) MPI_Init_thread(0, NULL, required, &provided);
164   Real_init();
165   return provided;
166 }
167 
168 
169 inline int
Init_thread(int & argc,char ** & argv,int required)170 MPI::Init_thread(int& argc, char**& argv, int required)
171 {
172   int provided;
173   (void) MPI_Init_thread(&argc, &argv, required, &provided);
174   Real_init();
175   return provided;
176 }
177 
178 
179 inline bool
Is_thread_main()180 MPI::Is_thread_main()
181 {
182   int flag;
183   (void) MPI_Is_thread_main(&flag);
184   return OPAL_INT_TO_BOOL(flag == 1);
185 }
186 
187 
188 inline int
Query_thread()189 MPI::Query_thread()
190 {
191   int provided;
192   (void) MPI_Query_thread(&provided);
193   return provided;
194 }
195 
196 
197 //
198 // Miscellany
199 //
200 
201 
202 inline void*
Alloc_mem(MPI::Aint size,const MPI::Info & info)203 MPI::Alloc_mem(MPI::Aint size, const MPI::Info& info)
204 {
205   void* baseptr;
206   (void) MPI_Alloc_mem(size, info, &baseptr);
207   return baseptr;
208 }
209 
210 
211 inline void
Free_mem(void * base)212 MPI::Free_mem(void* base)
213 {
214   (void) MPI_Free_mem(base);
215 }
216 
217 
218 //
219 // Process Creation
220 //
221 
222 
223 inline void
Close_port(const char * port_name)224 MPI::Close_port(const char* port_name)
225 {
226   (void) MPI_Close_port(const_cast<char *>(port_name));
227 }
228 
229 
230 inline void
Lookup_name(const char * service_name,const MPI::Info & info,char * port_name)231 MPI::Lookup_name(const char * service_name,
232 			const MPI::Info& info,
233 			char* port_name)
234 {
235   (void) MPI_Lookup_name(const_cast<char *>(service_name), info, port_name);
236 }
237 
238 
239 inline void
Open_port(const MPI::Info & info,char * port_name)240 MPI::Open_port(const MPI::Info& info, char* port_name)
241 {
242   (void) MPI_Open_port(info, port_name);
243 }
244 
245 
246 inline void
Publish_name(const char * service_name,const MPI::Info & info,const char * port_name)247 MPI::Publish_name(const char* service_name,
248 			 const MPI::Info& info,
249 			 const char* port_name)
250 {
251   (void) MPI_Publish_name(const_cast<char *>(service_name), info,
252                           const_cast<char *>(port_name));
253 }
254 
255 
256 inline void
Unpublish_name(const char * service_name,const MPI::Info & info,const char * port_name)257 MPI::Unpublish_name(const char* service_name,
258 			   const MPI::Info& info,
259 			   const char* port_name)
260 {
261   (void)MPI_Unpublish_name(const_cast<char *>(service_name), info,
262                            const_cast<char *>(port_name));
263 }
264 
265 
266 
267 //
268 // Profiling
269 //
270 
271 inline void
Pcontrol(const int level,...)272 MPI::Pcontrol(const int level, ...)
273 {
274   va_list ap;
275   va_start(ap, level);
276 
277   (void)MPI_Pcontrol(level, ap);
278   va_end(ap);
279 }
280 
281 
282 inline void
Get_version(int & version,int & subversion)283 MPI::Get_version(int& version, int& subversion)
284 {
285   (void)MPI_Get_version(&version, &subversion);
286 }
287 
288 
289 inline MPI::Aint
Get_address(void * location)290 MPI::Get_address(void* location)
291 {
292   MPI::Aint ret;
293   MPI_Get_address(location, &ret);
294   return ret;
295 }
296