44 _comm(c), _status( STATUS_NOCHANGE)
61 const std::string &intents,
65 if ( _func_map.find( fname) != _func_map.end())
67 (_name+
"."+fname,Window::init_function));
69 _func_map[fname] =
Function( func, intents, types, a, is_f90);
74 const std::string &intents,
80 (
_name+
"."+fname,Window::init_function));
86 new_attribute(
const std::string &aname,
const char loc,
const int type,
98 if ( loc !=
'w' && loc !=
'p' && loc !=
'e' && loc !=
'n' && loc !=
'c')
107 Attr_map::const_iterator it = _attr_map.find( aname);
109 if ( it != _attr_map.end() && ncomp > it->second->size_of_components()) {
111 "Cannot increase size of keywords");
112 delete_attribute( it->first);
113 it = _attr_map.end();
116 int id = (it==_attr_map.end())?_last_id:it->second->id();
120 new_attribute( aname,
id, loc, type, ncomp, unit);
121 _attr_map[aname] = a;
124 for (Pane_map::iterator it=_pane_map.begin(); it!=_pane_map.end(); ++it) {
130 if ( it == _attr_map.end()) _last_id =
id+ncomp+(ncomp>1);
132 if ( _status == STATUS_NOCHANGE) _status = STATUS_CHANGED;
139 Attr_map::iterator it = _attr_map.find( aname);
140 if ( it == _attr_map.end())
155 for (Pane_map::iterator it=_pane_map.begin(); it!=_pane_map.end(); ++it) {
162 _attr_map.erase( it);
163 if ( _last_id ==
id + ncomp+(ncomp>1)) {
165 if ( _status==STATUS_NOCHANGE) _status = STATUS_CHANGED;
168 _status = STATUS_SHRUNK;
177 _status = STATUS_CHANGED;
201 for (Pane_map::iterator it=_pane_map.begin(),
iend=_pane_map.end();
204 ( it->second->attribute( a->
id()), nitems, ng);
208 ((
Pane_friend&)pane(pid,
true)).set_size( a, nitems, ng);
213 void *addr,
int strd,
int cap,
bool is_const)
217 Pane &pn = pane(pane_id,
true);
225 &(
int*&)addr, strd, cap);
228 Attribute *a = pane( pane_id,
true).attribute( aname);
242 Pane &pn = pane(pane_id,
true);
252 Attribute *a = pane( pane_id,
true).attribute( aname);
265 Pane &pn = pane(pane_id,
true);
275 Attribute *a = pane( pane_id,
true).attribute( aname);
285 const void *val,
int v_strd,
int v_size)
throw(
COM_exception)
288 "append_array supports only window and pane attributes");
290 Attribute *a = pane( pane_id,
true).attribute( aname);
315 Pane &pn = pane(pane_id);
325 Attribute *a = pane( pane_id).attribute( aname);
335 int mode,
bool withghost,
340 if ( from->is_windowed())
return a;
350 if ( with_conn && aname.size() && from->name() != aname)
352 (from->fullname()+
" and " +aname,
355 if ( cond && cond->window()!=from->window()) {
357 (from->fullname()+
" and "+cond->fullname(),
361 for ( Pane_map::iterator ppit = ps.begin(); ppit!=ps.end(); ++ppit) {
362 Pane *ppn=ppit->second;
363 const int *cnd = NULL;
366 cnd = (
const int*)cond_pn->
pointer();
371 if ( !cond && (val==0 || val==ppn->
id()) || cnd && *cnd == val) {
377 Pane_map::iterator it = _pane_map.find( ppit->first);
378 pn = ( it!=_pane_map.end())?(
Pane_friend*)(it->second):NULL;
390 if ( _status == STATUS_SHRUNK) {
392 for (Attr_map::iterator it=_attr_map.begin(); it!=_attr_map.end(); ++it) {
393 int id = it->second->id(), ncomp=it->second->size_of_components();
394 max_id =
std::max( max_id,
id+ncomp+(ncomp>1));
396 if (max_id < _last_id) _last_id = max_id;
399 int npanes = _pane_map.size();
400 std::vector< int> pane_ids; pane_ids.reserve(npanes);
402 for (Pane_map::iterator it=_pane_map.begin(); it!=_pane_map.end(); ++it) {
403 it->second->init_done();
404 pane_ids.push_back( it->second->id());
407 _status = STATUS_NOCHANGE;
409 if ( !pane_changed) {
410 if ( npanes>
int(_pane_map.size())) {
418 int flag; MPI_Initialized( &flag);
419 if ( _comm == MPI_COMM_NULL) flag = 0;
423 if ( flag) MPI_Comm_size( _comm, &nprocs);
else nprocs = 1;
426 std::vector<int> npanes_all(nprocs);
428 MPI_Allgather( &npanes, 1, MPI_INT, &npanes_all[0], 1, MPI_INT, _comm);
430 npanes_all[0] = npanes;
432 std::vector<int> disps(nprocs+1);
434 for (
int i=0;
i<nprocs; ++
i) disps[
i+1] = disps[
i]+npanes_all[
i];
436 std::vector<int> pane_ids_all( disps[nprocs]);
438 MPI_Allgatherv( &pane_ids[0], npanes, MPI_INT, &pane_ids_all[0],
439 &npanes_all[0], &disps[0], MPI_INT, _comm);
441 pane_ids_all = pane_ids;
445 for (
int p=0; p<nprocs; ++p) {
446 for (
int j=disps[p], jn=disps[p+1];
j<jn; ++
j)
447 _proc_map[ pane_ids_all[
j]] = p;
454 "init_done must be called before owner_rank is called");
456 Proc_map::const_iterator it =
_proc_map.find( pane_id);
458 else return it->second;
467 if ( loc) *loc =
'p';
472 if ( unit) *unit =
"";
477 Attr_map::const_iterator it = _attr_map.find( aname);
478 if ( it == _attr_map.end())
487 if ( unit) *unit = a.
unit();
492 template <
class Attr>
496 if ( pid==0 && a->location() !=
'w')
500 if ( nitem) *nitem = a->size_of_items();
501 if ( ng) *ng = a->size_of_ghost_items();
517 const COM::Connectivity *conn = pn->
connectivity( aname);
525 const COM::Attribute *attr = pn->
attribute( aname);
537 if ( aname.empty()) {
538 Pane_map::const_iterator pit = _pane_map.find( pid);
539 if ( pit == _pane_map.end())
return -1;
553 const COM::Connectivity *conn = pn->
connectivity( aname);
554 if ( conn==NULL)
return -1;
555 else return conn->
status();
559 const COM::Attribute *attr = pn->
attribute( aname);
560 if ( attr==NULL)
return -1;
561 else return attr->
status();
576 const COM::Connectivity *conn = pn->
connectivity( aname);
581 conn = conn->parent();
582 if ( conn==NULL) parent.clear();
583 else parent = conn->fullname();
587 const COM::Attribute *attr = pn->
attribute( aname);
592 if ( attr==NULL) parent.clear();
593 else parent = attr->fullname();
601 template <
class Attr>
605 if ( !is_const && a->is_const() )
609 if ( pid==0 && a->location() !=
'w')
613 addr.ptr = (
void*)(a->pointer());
615 addr.n1 = a->capacity()*a->stride();
617 else if ( addr.dim == 2) {
618 if ( a->stride()>=a->size_of_components()) {
619 addr.n1 = a->stride();
620 addr.n2 = a->capacity();
623 addr.n1 = a->capacity();
624 addr.n2 = a->size_of_components();
629 if ( addr.dim==0 && (a->capacity()!=1 || a->size_of_components()!=1))
637 if ( cap) *cap = a->capacity();
638 if ( strd) *strd = a->stride();
673 template <
class Attr>
677 if ( pid==0 && a->location() !=
'w')
679 ( a->fullname(), Window::copy_size));
681 const_cast<Attr*
>(a)->copy_array( val, v_strd, v_size,
686 void *val,
int v_strd,
int v_size,
703 val, v_strd, v_size,
offset);
712 val, v_strd, v_size,
offset);
722 if ( a->location()==
'w')
724 ((
Pane_friend&)_dummy).reinit_attr( aid, op, addr, strd, cap);
727 Pane *pn = a->pane();
729 ((
Pane_friend*)pn)->reinit_attr( aid, op, addr, strd, cap);
736 for (Pane_map::iterator it=_pane_map.begin(),
iend=_pane_map.end();
738 ((
Pane_friend*)it->second)->reinit_attr( aid, op, NULL, strd, cap);
740 if ( addr) *addr= NULL;
751 Pane *pn = con->pane();
755 for (Pane_map::iterator it=_pane_map.begin(),
iend=_pane_map.end();
759 ((
Pane_friend*)it->second)->reinit_conn( c, op, NULL, strd, cap);
761 if ( addr) *addr= NULL;
765 ((
Pane_friend*)pn)->reinit_conn( con, op, addr, strd, cap);
771 if ( pid==0)
return _dummy;
774 Pane_map::iterator pit = _pane_map.find( pid);
775 if ( pit == _pane_map.end()) {
777 return *(_pane_map[pid] =
new Pane( &_dummy, pid));
780 std::cerr <<
"No such Pane ID: " << pid << std::endl;
781 std::cerr <<
"While the known Pane IDs are: [ ";
782 Pane_map::iterator pit;
783 for ( pit=_pane_map.begin(); pit != _pane_map.end(); ++pit)
784 std::cerr << pit->first <<
" ";
785 std::cerr <<
"]" << std::endl;
796 if ( pid==0)
return _dummy;
799 Pane_map::const_iterator pit = _pane_map.find( pid);
800 if ( pit == _pane_map.end()) {
818 pane_ids.push_back( it->first);
822 "Can only obtain panes after calling window_init_done");
824 std::map<int,int>::const_iterator it,
iend;
826 if ( rank==-1 || it->second == rank)
827 pane_ids.push_back( it->first);
838 ps.push_back( it->second);
845 Attr_map::iterator it = _attr_map.find( aname);
846 if ( it == _attr_map.end())
852 std::string::size_type start = aname.find(
'-');
853 if ( start == aname.npos)
857 Attr_map::iterator it = _attr_map.find( &aname[start+1]);
859 if ( it != _attr_map.end()) {
863 int i = std::atoi( aname.c_str());
868 return attribute( att->
id()+
i);
879 Func_map::iterator it =
_func_map.find( fname);
void inherit(Attribute *a, bool clone, bool withghost, int depth=0)
Inherit from parent. If depth>0, then the procedure is for the subcomponents.
int COM_Type
Indices for derived data types.
A Pane object contains a mesh, pane attribute, and field variables.
bool size_set() const
Returns whether the size for the attribute has been set.
void delete_attribute(const std::string &aname)
Delete an existing Attribute object.
void alloc_array(const std::string &aname, const int pane_id, void **addr, int strd=0, int cap=0)
Allocate memory for an attribute for a specific pane and set addr to the address. ...
A Function object corresponds to a function member of a window.
#define COM_assertion(EX)
Error checking utility similar to the assert macro of the C language.
An Attribute object is a data member of a window.
int get_status(const std::string &aname, int pane_id) const
Get the status of an attribute or pane.
void set_array(const std::string &aname, const int pane_id, void *addr, int strd=0, int cap=0, bool is_const=false)
Associate an array with an attribute for a specific pane.
static bool is_digit(char c)
#define COM_assertion_msg(EX, msg)
Connectivity * parent()
Parent attribute being used.
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
void copy_array(const std::string &aname, const int pane_id, void *val, int v_strd=0, int v_size=0, int offset=0) const
Copy an attribute on a specific pane into a given array.
bool is_windowed() const
Checks whether the attribute is associated with the window.
void get_size(const std::string &aname, int pane_id, int *nitems, int *ng) const
Get the sizes of an attribute for a specific pane.
int _status
Status of the window.
void set_size(Attribute *a, int nitems, int ng)
Set the size of an attribute.
int status() const
Obtain the status of the attribute.
std::map< int, Pane * > Pane_map
void get_array_common(const Attr *a, int pid, Window::Pointer_descriptor &addr, int *strd, int *cap, bool is_const)
Function * function(const std::string &f)
Obtain the function pointer from its name.
void delete_attribute(int id)
Delete an existing attribute with given id.
real *8 function offset(vNorm, x2, y2, z2)
void resize_array(const std::string &aname, const int pane_id, void **addr, int strd=-1, int cap=0)
Resize memory for an attribute for a specific pane and set addr to the address.
const Window * window() const
Obtain a constant pointer to the parent window of the attribute.
Shorter_size location() const
Obtain the location of the attribute.
static const int * get_size_info(const std::string &aname)
Obtain the size info of pre-defined connectivity.
Encapsulates the states of an exception.
Attribute * attribute(const std::string &a)
Obtain the attribute from given name.
const std::string & unit() const
Obtain the unit of the attribute.
void get_array(const std::string &aname, const int pane_id, Pointer_descriptor &addr, int *strd=NULL, int *cap=NULL, bool is_const=false)
Get the address associated with an attribute for a specific pane.
std::string msg
Error message.
Attribute * get_attribute(const std::string &aname, char *l, int *t, int *n, std::string *u) const
Get the meta-information about an attribute.
const void * pointer() const
Obtain a constant pointer to the physical address.
void reinit_conn(Connectivity *con, OP_Init op, int **addr=NULL, int strd=0, int cap=0)
Template implementation for setting (op==OP_SET or OP_SET_CONST), allocating (op==OP_ALLOC), resizing (op==OP_RESIZE) and deallocating (op==OP_DEALLOC) an array for a specific connectivity table.
Proc_map _proc_map
Map from pane ID to process ranks.
Attr_map _attr_map
Map from attribute names to their metadata.
**********************************************************************Rocstar Simulation Suite Illinois Rocstar LLC All rights reserved ****Illinois Rocstar LLC IL **www illinoisrocstar com **sales illinoisrocstar com WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **Arising OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE **********************************************************************INTERFACE SUBROUTINE knode iend
Attribute * new_attribute(const std::string &aname, const char loc, const int type, int ncomp, const std::string &unit)
Create a new Attribute object with given properties.
void get_size_common(const Attr *a, int pid, int *nitem, int *ng)
void copy_array_common(const Attr *a, int pid, void *val, int v_strd, int v_size, int offset)
void(* Func_ptr)()
Pointer of functions.
const std::string & name() const
Obtain the name of the attribute.
void reinit_attr(int aid, OP_Init op, void **addr, int strd, int cap)
Window(const std::string &name, MPI_Comm c)
Create a window with a given name and MPI communicator.
static bool is_element_name(const std::string &aname)
void init_done(bool pane_changed=true)
Perform some final checking of the window.
void dealloc_array(const std::string &aname, const int pane_id=0)
Deallocate memory for an attribute for a specific pane if allocated by Roccom.
void reinit_attr(Attribute *attr, OP_Init op, void **addr=NULL, int strd=0, int cap=0)
Implementation for setting (op==OP_SET or OP_SET_CONST), allocating (op==OP_ALLOC), resizing (op==OP_RESIZE) and deallocating (op==OP_DEALLOC) an array for a specific attribute.
This file contains a set of routines for error assertion.
void get_parent(const std::string &aname, int pane_id, std::string &name) const
Get the parent name of an attribute and load into name.
int owner_rank(const int pane_id) const
Obtain the process rank that owns a given pane.
int stride() const
Obtain the stride of the attribute in base datatype.
void set_size(int nitems, int ngitems=0)
Set the size of items and ghost items.
std::string _name
Name of the window.
void append_array(const std::string &aname, const int pane_id, const void *val, int v_strd, int v_size)
Append the given array to the end of the attribute on a specific pane, and reallocate memory for the ...
Attribute * attribute(const std::string &a)
Obtain a pointer to the attribute metadata from its name.
#define append_frame(s, frame)
Macro for appending the information about the given frame to the string s.
Pane & pane(const int pane_id, bool insert=false)
Find the pane with given ID. If not found, insert a pane with given ID.
unsigned long id(const Leda_like_handle &x)
Connectivity * connectivity(Size i)
Obtain the connectivity table containing the element with the given ID.
void set_size(const std::string &aname, int pane_id, int nitems, int ng=0)
Set the sizes of an attribute for a specific pane.
Func_map _func_map
Map from function names to their metadata.
Attribute * new_attribute(const std::string &aname, int aid, const char loc, const int type, int ncomp, const std::string &unit)
Attribute * inherit(Attribute *from, const std::string &aname, int mode, bool withghost)
Inherit an attribute from another pane onto the current pane:
virtual ~Window()
Destructor.
Pane_map _pane_map
Map from pane ID to their metadata.
COM_Type data_type() const
Obtain the data type of each component of the attribute.
int id() const
Obtain the id (or index) of the attribute.
void panes(std::vector< int > &ps, int rank=-2)
Obtain all the local panes of the window.
Attribute * inherit(Attribute *from, const std::string &aname, int inherit_mode, bool withghost, const Attribute *cond, int val)
Inherit the attributes of another window with a different name.
Contains the prototypes for the Window object.
Encapsulates an element-connectivity of a mesh.
int id() const
Get the ID of the pane.
int size_of_items() const
Obtain the number of items in the attribute.
void set_function(const std::string &fname, Func_ptr func, const std::string &intents, const COM_Type *types, Attribute *a, bool if_f90=false)
Initialize a Function record.
int size_of_components() const
Obtain the number of components in the attribute.
void append_array(const void *from, int strd, int nitem)