Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Function.h
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 // $Id: Function.h,v 1.10 2010/03/12 00:38:32 gzagaris Exp $
24 
29 /* Author: Xiangmin Jiao */
30 
31 #ifndef __ROCCOM_FUNCTION_H__
32 #define __ROCCOM_FUNCTION_H__
33 
34 #include <string>
35 #include <vector>
36 #include "commpi.h"
37 #include "roccom_basic.h"
38 #include "roccom_exception.h"
39 #include "roccom_assertion.h"
40 
41 COM_BEGIN_NAME_SPACE
42 
43 class Attribute;
44 
49 class Function {
50 public:
51  enum { MAX_NUMARG=14};
53 
57  Function() : _ptr(NULL), _attr(NULL), _comm(MPI_COMM_NULL),
59  _ftype(C_FUNC) {}
77  Function( Func_ptr p, const std::string &s, const int *t,
78  Attribute *a, bool b=false)
79  : _ptr(p), _intents(s), _types( t, t+s.size()), _attr(a),
80  _comm(MPI_COMM_NULL), _ftype( b?F_FUNC:C_FUNC) {}
81  Function( Member_func_ptr p, const std::string &s, const int *t,
82  Attribute *a)
83  : _mem_ptr(p), _intents(s), _types( t, t+s.size()), _attr(a),
84  _comm(MPI_COMM_NULL),_ftype(CPP_MEMBER) {}
85  //\}
86 
90  Func_ptr pointer() { return _ptr; }
93  int num_of_args() const { return _intents.size(); }
95  bool is_input( int i) const
96  { return _intents[i]!='o' && _intents[i]!='O'; }
98  bool is_output( int i) const
99  { return _intents[i]!='i' && _intents[i]!='I'; }
101  bool is_literal( int i) const
102  { return _types[i] != COM_RAWDATA && _types[i] != COM_F90POINTER &&
103  _types[i] != COM_METADATA; }
105  bool is_optional( int i) const
106  { return _intents[i]>='A' && _intents[i]<='Z'; }
108  bool is_rawdata( int i) const
109  { return _types[i] == COM_RAWDATA || _types[i] == COM_F90POINTER; }
111  bool is_metadata( int i) const
112  { return _types[i] == COM_METADATA; }
113 
114  bool is_fortran() const { return _ftype==F_FUNC; }
115  COM_Type data_type( int i) const { return _types[i]; }
116  char intent( int i) const { return _intents[i]; }
117 
118  void set_communicator( MPI_Comm c) { _comm = c; }
119  MPI_Comm communicator() const { return _comm; }
120 
121  Attribute *attribute() { return _attr; }
122  //\}
123 
127 #ifndef DOXYGEN_SHOULD_SKIP_THIS
128  // invoke with no argument
129  void operator()() { _ptr(); }
130  // invoke with 1 argument
131  void operator()(void *a1) {
132  if ( _ftype!=CPP_MEMBER) {
133  typedef void(*Func1)(void*);
134  (*(Func1)(_ptr))(a1);
135  }
136  else {
137  typedef void(COM_Object::*Member_Func1)();
138  Member_Func1 f = (Member_Func1)_mem_ptr;
139  validate_object( a1);
140  (reinterpret_cast<COM_Object*>(a1)->*f)();
141  }
142  }
143  // invoke with 2 arguments
144  void operator()(void *a1, void *a2) {
145  if ( _ftype!=CPP_MEMBER) {
146  typedef void(*Func2)(void*,void*);
147  (*(Func2)(_ptr))(a1,a2);
148  }
149  else {
150  typedef void(COM_Object::*Member_Func2)(void*);
151  Member_Func2 f = (Member_Func2)_mem_ptr;
152  validate_object(a1);
153  (reinterpret_cast<COM_Object*>(a1)->*f)(a2);
154  }
155  }
156  // invoke with 3 arguments
157  void operator()( void *a1, void *a2, void *a3) {
158  if ( _ftype!=CPP_MEMBER) {
159  typedef void(*Func3)(void*,void*,void*);
160  (*(Func3)(_ptr))(a1,a2,a3);
161  }
162  else {
163  typedef void(COM_Object::*Member_Func3)(void*,void*);
164  Member_Func3 f = (Member_Func3)_mem_ptr;
165  validate_object(a1);
166  (reinterpret_cast<COM_Object*>(a1)->*f)(a2,a3);
167  }
168  }
169 
170  // invoke with 4 arguments
171  void operator()( void *a1, void *a2, void *a3, void *a4) {
172  if ( _ftype!=CPP_MEMBER) {
173  typedef void(*Func4)(void*,void*,void*,void*);
174  (*(Func4)(_ptr))(a1,a2,a3,a4);
175  }
176  else {
177  typedef void(COM_Object::*Member_Func4)(void*,void*,void*);
178  Member_Func4 f = (Member_Func4)_mem_ptr;
179  validate_object( a1);
180  (reinterpret_cast<COM_Object*>(a1)->*f)(a2,a3,a4);
181  }
182  }
183 
184  // invoke with 5 arguments
185  void operator()( void *a1, void *a2, void *a3, void *a4, void *a5) {
186  if ( _ftype!=CPP_MEMBER) {
187  typedef void(*Func5)(void*,void*,void*,void*,void*);
188  (*(Func5)(_ptr))(a1,a2,a3,a4,a5);
189  }
190  else {
191  typedef void(COM_Object::*Member_Func5)(void*,void*,void*,void*);
192  Member_Func5 f = (Member_Func5)_mem_ptr;
193  validate_object( a1);
194  (reinterpret_cast<COM_Object*>(a1)->*f)(a2,a3,a4,a5);
195  }
196  }
197 
198  // invoke with 6 arguments
199  void operator()( void *a1, void *a2, void *a3, void *a4, void *a5,
200  void *a6) {
201  if ( _ftype!=CPP_MEMBER) {
202  typedef void(*Func6)(void*,void*,void*,void*,void*,void*);
203  (*(Func6)(_ptr))(a1,a2,a3,a4,a5,a6);
204  }
205  else {
206  typedef void(COM_Object::*Member_Func6)(void*,void*,void*,void*,void*);
207  Member_Func6 f = (Member_Func6)_mem_ptr;
208  validate_object( a1);
209  (reinterpret_cast<COM_Object*>(a1)->*f)(a2,a3,a4,a5,a6);
210  }
211  }
212 
213  // invoke with 7 arguments
214  void operator()( void *a1, void *a2, void *a3, void *a4, void *a5,
215  void *a6, void *a7) {
216  if ( _ftype!=CPP_MEMBER) {
217  typedef void(*Func7)(void*,void*,void*,void*,void*,void*,void*);
218  (*(Func7)(_ptr))(a1,a2,a3,a4,a5,a6,a7);
219  }
220  else {
221  typedef void(COM_Object::*Member_Func7)(void*,void*,void*,void*,
222  void*,void*);
223  Member_Func7 f = (Member_Func7)_mem_ptr;
224  validate_object( a1);
225  (reinterpret_cast<COM_Object*>(a1)->*f)(a2,a3,a4,a5,a6,a7);
226  }
227  }
228 
229  // invoke with 8 arguments
230  void operator()( void *a1, void *a2, void *a3, void *a4, void *a5,
231  void *a6, void *a7, void *a8) {
232  if ( _ftype!=CPP_MEMBER) {
233  typedef void(*Func8)(void*,void*,void*,void*,void*,void*,void*,void*);
234  (*(Func8)(_ptr))(a1,a2,a3,a4,a5,a6,a7,a8);
235  }
236  else {
237  typedef void(COM_Object::*Member_Func8)(void*,void*,void*,void*,
238  void*,void*,void*);
239  Member_Func8 f = (Member_Func8)_mem_ptr;
240  validate_object( a1);
241  (reinterpret_cast<COM_Object*>(a1)->*f)(a2,a3,a4,a5,a6,a7,a8);
242  }
243  }
244 
245  // invoke with 9 arguments
246  void operator()( void *a1, void *a2, void *a3, void *a4, void *a5,
247  void *a6, void *a7, void *a8, void *a9) {
248  if ( _ftype!=CPP_MEMBER) {
249  typedef void(*Func9)(void*,void*,void*,void*,void*,void*,
250  void*,void*,void*);
251  (*(Func9)(_ptr))(a1,a2,a3,a4,a5,a6,a7,a8,a9);
252  }
253  else {
254  typedef void(COM_Object::*Member_Func9)(void*,void*,void*,void*,void*,
255  void*,void*,void*);
256  Member_Func9 f = (Member_Func9)_mem_ptr;
257  validate_object( a1);
258  (reinterpret_cast<COM_Object*>(a1)->*f)(a2,a3,a4,a5,a6,a7,a8,a9);
259  }
260  }
261 
262  // invoke with 10 arguments
263  void operator()( void *a1, void *a2, void *a3, void *a4, void *a5,
264  void *a6, void *a7, void *a8, void *a9, void *a10) {
265  if ( _ftype!=CPP_MEMBER) {
266  typedef void(*Func10)(void*,void*,void*,void*,void*,void*,
267  void*,void*,void*,void*);
268  (*(Func10)(_ptr))(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10);
269  }
270  else {
271  typedef void(COM_Object::*Member_Func10)(void*,void*,void*,void*,void*,
272  void*,void*,void*,void*);
273  Member_Func10 f = (Member_Func10)_mem_ptr;
274  validate_object( a1);
275  (reinterpret_cast<COM_Object*>(a1)->*f)(a2,a3,a4,a5,a6,a7,a8,a9,a10);
276  }
277  }
278 
279  // invoke with 11 arguments
280  void operator()( void *a1, void *a2, void *a3, void *a4, void *a5, void *a6,
281  void *a7, void *a8, void *a9, void *a10, void *a11) {
282  if ( _ftype!=CPP_MEMBER) {
283  typedef void(*Func11)(void*,void*,void*,void*,void*,void*,
284  void*,void*,void*,void*,void*);
285  (*(Func11)(_ptr))(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11);
286  }
287  else {
288  typedef void(COM_Object::*Member_Func11)(void*,void*,void*,void*,void*,
289  void*,void*,void*,void*,void*);
290  Member_Func11 f = (Member_Func11)_mem_ptr;
291  validate_object( a1);
292  (reinterpret_cast<COM_Object*>(a1)->*f)(a2,a3,a4,a5,a6,a7,a8,a9,a10,a11);
293  }
294  }
295 
296  // invoke with 12 arguments
297  void operator()( void *a1, void *a2, void *a3, void *a4, void *a5, void *a6,
298  void *a7, void *a8, void *a9, void *a10, void *a11, void *a12 )
299  {
300 
301  if ( _ftype!=CPP_MEMBER) {
302  typedef void(*Func11)(void*,void*,void*,void*,void*,void*,
303  void*,void*,void*,void*,void*,void*);
304  (*(Func11)(_ptr))(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12);
305  }
306  else {
307  typedef void(COM_Object::*Member_Func11)(void*,void*,void*,void*,void*,
308  void*,void*,void*,void*,void*,void*);
309  Member_Func11 f = (Member_Func11)_mem_ptr;
310  validate_object( a1);
311  (reinterpret_cast<COM_Object*>(a1)->*f)(a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12);
312  }
313 
314  }
315 
316  // invoke with 13 arguments
317  void operator()( void *a1, void *a2, void *a3, void *a4, void *a5, void *a6,
318  void *a7, void *a8, void *a9, void *a10, void *a11, void* a12, void *a13 )
319  {
320 
321  if ( _ftype!=CPP_MEMBER) {
322  typedef void(*Func11)(void*,void*,void*,void*,void*,void*,
323  void*,void*,void*,void*,void*,void*,void*);
324  (*(Func11)(_ptr))(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13);
325  }
326  else {
327  typedef void(COM_Object::*Member_Func11)(void*,void*,void*,void*,void*,
328  void*,void*,void*,void*,void*,void*,void*);
329  Member_Func11 f = (Member_Func11)_mem_ptr;
330  validate_object( a1);
331  (reinterpret_cast<COM_Object*>(a1)->*f)(a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13);
332  }
333  }
334 
335  // invoke with 14 arguments
336  void operator()( void *a1, void *a2, void *a3, void *a4, void *a5, void *a6,
337  void *a7, void *a8, void *a9, void *a10, void *a11, void* a12, void *a13, void *a14 )
338  {
339 
340  if ( _ftype!=CPP_MEMBER) {
341  typedef void(*Func11)(void*,void*,void*,void*,void*,void*,
342  void*,void*,void*,void*,void*,void*,void*,void*);
343  (*(Func11)(_ptr))(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14);
344  }
345  else {
346  typedef void(COM_Object::*Member_Func11)(void*,void*,void*,void*,void*,
347  void*,void*,void*,void*,void*,void*,void*,void*);
348  Member_Func11 f = (Member_Func11)_mem_ptr;
349  validate_object( a1);
350  (reinterpret_cast<COM_Object*>(a1)->*f)(a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14);
351  }
352  }
353 
354 #endif
355 
357  void operator()( int n, void **ps) throw (COM_exception)
358  {
359 
360  switch ( n)
361  {
362  case 0: operator()(); break;
363  case 1: operator()( ps[0] ); break;
364  case 2: operator()( ps[0],ps[1] ); break;
365  case 3: operator()( ps[0],ps[1],ps[2] ); break;
366  case 4: operator()( ps[0],ps[1],ps[2],ps[3] ); break;
367  case 5: operator()( ps[0],ps[1],ps[2],ps[3],ps[4] ); break;
368  case 6: operator()( ps[0],ps[1],ps[2],ps[3],ps[4],ps[5] ); break;
369  case 7: operator()( ps[0],ps[1],ps[2],ps[3],ps[4],ps[5],ps[6] ); break;
370  case 8: operator()( ps[0],ps[1],ps[2],ps[3],ps[4],ps[5],ps[6],ps[7] ); break;
371  case 9: operator()( ps[0],ps[1],ps[2],ps[3],ps[4],ps[5],ps[6],ps[7],ps[8] ); break;
372  case 10:operator()( ps[0],ps[1],ps[2],ps[3],ps[4],ps[5],ps[6],ps[7],ps[8],ps[9] ); break;
373  case 11:operator()( ps[0],ps[1],ps[2],ps[3],ps[4],ps[5],ps[6],ps[7],ps[8],ps[9],ps[10] ); break;
374  case 12:operator()( ps[0],ps[1],ps[2],ps[3],ps[4],ps[5],ps[6],ps[7],ps[8],ps[9],ps[10],ps[11] ); break;
375  case 13:operator()( ps[0],ps[1],ps[2],ps[3],ps[4],ps[5],ps[6],ps[7],ps[8],ps[9],ps[10],ps[11],ps[12] ); break;
376  case 14:operator()( ps[0],ps[1],ps[2],ps[3],ps[4],ps[5],ps[6],ps[7],ps[8],ps[9],ps[10],ps[11],ps[12],ps[13] ); break;
377  default: throw COM_exception(COM_ERR_TOO_MANY_ARGS);
378  }
379 
380  }
381 
382  //\}
383 private:
384  void validate_object( void *a1) {
385  int ierr = reinterpret_cast<COM_Object*>(a1)->validate_object(a1);
386  switch ( ierr) {
387  case 1: COM_assertion_msg( ierr==0, "Invalid pointer after casting");
388  case 3: COM_assertion_msg( ierr==0, "Invalid pointer and cookie after casting");
389  default:;
390  }
391  }
392 
393 #ifndef DOXYGEN_SHOULD_SKIP_THIS
394  union {
396  Member_func_ptr _mem_ptr;
397  };
398  std::string _intents;
399  std::vector<COM_Type> _types;
402  MPI_Comm _comm;
403  int _ftype;
404 #endif
405 };
406 
407 COM_END_NAME_SPACE
408 
409 #endif
410 
411 
void set_communicator(MPI_Comm c)
Definition: Function.h:118
int COM_Type
Indices for derived data types.
Definition: roccom_basic.h:122
bool is_output(int i) const
Check whether the ith argument is for output.
Definition: Function.h:98
void operator()(void *a1, void *a2, void *a3, void *a4)
Definition: Function.h:171
A Function object corresponds to a function member of a window.
Definition: Function.h:49
bool is_optional(int i) const
Check whether the ith argument is optional.
Definition: Function.h:105
Function(Member_func_ptr p, const std::string &s, const int *t, Attribute *a)
Definition: Function.h:81
bool is_fortran() const
Definition: Function.h:114
An Attribute object is a data member of a window.
Definition: Attribute.h:51
#define COM_assertion_msg(EX, msg)
double s
Definition: blastest.C:80
void operator()(void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, void *a7, void *a8, void *a9, void *a10, void *a11, void *a12, void *a13, void *a14)
Definition: Function.h:336
void operator()(void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, void *a7, void *a8, void *a9, void *a10, void *a11)
Definition: Function.h:280
This file contains some definitions of macros and constants for Roccoms.
Encapsulates the states of an exception.
void operator()(void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, void *a7, void *a8, void *a9, void *a10)
Definition: Function.h:263
MPI_Comm communicator() const
Definition: Function.h:119
std::string _intents
Intention of the argument.
Definition: Function.h:398
void operator()()
Definition: Function.h:129
int _ftype
Indicate the type of the function.
Definition: Function.h:403
void operator()(void *a1, void *a2, void *a3, void *a4, void *a5)
Definition: Function.h:185
bool is_metadata(int i) const
Check whether the ith argument is meta.
Definition: Function.h:111
void(* Func_ptr)()
Pointer of functions.
Definition: roccom_basic.h:123
bool is_literal(int i) const
Check whether the ith argument is literal type.
Definition: Function.h:101
Attribute * attribute()
Definition: Function.h:121
blockLoc i
Definition: read.cpp:79
COM_Type data_type(int i) const
Definition: Function.h:115
void operator()(void *a1, void *a2, void *a3)
Definition: Function.h:157
Contains declarations of MPI subroutines used in Roccom.
This file contains a set of routines for error assertion.
const NT & n
Attribute * _attr
Member function.
Definition: Function.h:401
void operator()(void *a1, void *a2, void *a3, void *a4, void *a5, void *a6)
Definition: Function.h:199
void operator()(void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, void *a7)
Definition: Function.h:214
Member_func_ptr _mem_ptr
Pointer to a member function.
Definition: Function.h:396
char intent(int i) const
Definition: Function.h:116
void operator()(void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, void *a7, void *a8)
Definition: Function.h:230
Func_ptr pointer()
Get physical address of the function.
Definition: Function.h:91
bool is_input(int i) const
Check whether the ith argument is for input.
Definition: Function.h:95
void operator()(void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, void *a7, void *a8, void *a9, void *a10, void *a11, void *a12, void *a13)
Definition: Function.h:317
void operator()(void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, void *a7, void *a8, void *a9)
Definition: Function.h:246
MPI_Comm _comm
Definition: Function.h:402
int num_of_args() const
Get the number of arguments.
Definition: Function.h:93
Function(Func_ptr p, const std::string &s, const int *t, Attribute *a, bool b=false)
Create a function object with physical address p.
Definition: Function.h:77
std::vector< COM_Type > _types
Data type of the arguments.
Definition: Function.h:400
Function()
Default constructor.
Definition: Function.h:58
bool is_rawdata(int i) const
Check whether the ith argument is raw.
Definition: Function.h:108
void operator()(void *a1)
Definition: Function.h:131
void operator()(void *a1, void *a2)
Definition: Function.h:144
void operator()(int n, void **ps)
invoke with an array of arguments
Definition: Function.h:357
Func_ptr _ptr
Pointer to a regular function.
Definition: Function.h:395
void validate_object(void *a1)
Definition: Function.h:384
void operator()(void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, void *a7, void *a8, void *a9, void *a10, void *a11, void *a12)
Definition: Function.h:297