Galois
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GlobalObj.h
Go to the documentation of this file.
1 /*
2  * This file belongs to the Galois project, a C++ library for exploiting
3  * parallelism. The code is being released under the terms of the 3-Clause BSD
4  * License (a copy is located in LICENSE.txt at the top-level directory).
5  *
6  * Copyright (C) 2018, The University of Texas at Austin. All rights reserved.
7  * UNIVERSITY EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES CONCERNING THIS
8  * SOFTWARE AND DOCUMENTATION, INCLUDING ANY WARRANTIES OF MERCHANTABILITY,
9  * FITNESS FOR ANY PARTICULAR PURPOSE, NON-INFRINGEMENT AND WARRANTIES OF
10  * PERFORMANCE, AND ANY WARRANTY THAT MIGHT OTHERWISE ARISE FROM COURSE OF
11  * DEALING OR USAGE OF TRADE. NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH
12  * RESPECT TO THE USE OF THE SOFTWARE OR DOCUMENTATION. Under no circumstances
13  * shall University be liable for incidental, special, indirect, direct or
14  * consequential damages or loss of profits, interruption of business, or
15  * related expenses which may arise from use of Software or Documentation,
16  * including but not limited to those resulting from defects in Software and/or
17  * Documentation, or loss or inaccuracy of data of any kind.
18  */
19 
27 #include <vector>
28 #include <cstdint>
29 #include <cassert>
30 
31 #ifndef _GALOIS_DIST_GLOBAL_OBJECT_H
32 #define _GALOIS_DIST_GLOBAL_OBJECT_H
33 
34 namespace galois {
35 namespace runtime {
36 
43 class GlobalObject {
46  static std::vector<uintptr_t> allobjs;
48  uint32_t objID;
49 
50 protected:
51  GlobalObject(const GlobalObject&) = delete;
52  GlobalObject(GlobalObject&&) = delete;
53 
60  static uintptr_t ptrForObj(unsigned oid);
61 
72  template <typename T>
73  GlobalObject(const T* ptr) {
74  objID = allobjs.size();
75  allobjs.push_back(reinterpret_cast<uintptr_t>(ptr));
76  }
77 
83  uint32_t idForSelf() const { return objID; }
84 };
85 
86 } // end namespace runtime
87 } // end namespace galois
88 
89 #endif //_GALOIS_DIST_GLOBAL_OBJECT_H
uint32_t idForSelf() const
Returns own global id.
Definition: GlobalObj.h:83
static uintptr_t ptrForObj(unsigned oid)
Returns the pointer for a global object.
Definition: GlobalObj.cpp:31
A class to be inherited from so that all child classes will have a tracked unique ID...
Definition: GlobalObj.h:43
GlobalObject(const T *ptr)
Constructs a global object given a pointer to the object you want to make a global object...
Definition: GlobalObj.h:73
GlobalObject(const GlobalObject &)=delete