-
Notifications
You must be signed in to change notification settings - Fork 248
How to use "Smart Pointers" within Kratos
All the memory management within Kratos is done through "Shared Pointers". Essentially a shared pointer is an entity which holds a counter with the number of existing instances of an object. EVERY TIME a new Shared Pointer is created such counter is incremented or decremented to represent the number of living instances of the object pointed to.
A good description of the design and behaviour of shared_ptr
can be found at the links:
In the practice when using Shared Pointers within Kratos one should be aware of their performance pitfalls so to be able to avoid them.
The use of an existing pointer does not imply any performance penalty with respect to a traditional pointer, HOWEVER while creating and destroying a traditional "c-style" pointer is a cheap operation, the creation or destruction of a shared point is relatively time consuming. This is so, as at the moment of creating/destructing a Shared Pointer the number of references to the object should be incremented or decremented, which implies an atomic operation if OpenMP parallelism is employed.
Within Kratos the great majority of shared_ptrs is stored in vectors, typically in the classes:
- PointerVector (used as a basis for the "geometry" class)
- PointerVectorSet (NodesContainerType, ElementsContainerType, ConditionsContainerType)
- PointerVectorMap
All of such objects provide two distinct operators, [] and ().
It returns a reference to the object pointed by the underlying pointer. This operator should be used in most cases.
It returns a pointer to the object, which will often require creating a copy of the pointer. This is often slow, only use it if you really need a pointer.
Similarly, avoid using GetGeometry().pGetNode(...) unless you really need a pointer, since this will imply allocating a new pointer and is hence an expensive operation.
- Getting Kratos (Last compiled Release)
- Compiling Kratos
- Running an example from GiD
- Kratos input files and I/O
- Data management
- Solving strategies
- Manipulating solution values
- Multiphysics
- Video tutorials
- Style Guide
- Authorship of Kratos files
- Configure .gitignore
- How to configure clang-format
- How to use smart pointer in Kratos
- How to define adjoint elements and response functions
- Visibility and Exposure
- Namespaces and Static Classes
Kratos structure
Conventions
Solvers
Debugging, profiling and testing
- Compiling Kratos in debug mode
- Debugging Kratos using GDB
- Cross-debugging Kratos under Windows
- Debugging Kratos C++ under Windows
- Checking memory usage with Valgind
- Profiling Kratos with MAQAO
- Creating unitary tests
- Using ThreadSanitizer to detect OMP data race bugs
- Debugging Memory with ASAN
HOW TOs
- How to create applications
- Python Tutorials
- Kratos For Dummies (I)
- List of classes and variables accessible via python
- How to use Logger
- How to Create a New Application using cmake
- How to write a JSON configuration file
- How to Access DataBase
- How to use quaternions in Kratos
- How to do Mapping between nonmatching meshes
- How to use Clang-Tidy to automatically correct code
- How to use the Constitutive Law class
- How to use Serialization
- How to use GlobalPointerCommunicator
- How to use PointerMapCommunicator
- How to use the Geometry
- How to use processes for BCs
- How to use Parallel Utilities in futureproofing the code
- Porting to Pybind11 (LEGACY CODE)
- Porting to AMatrix
- How to use Cotire
- Applications: Python-modules
- How to run multiple cases using PyCOMPSs
- How to apply a function to a list of variables
- How to use Kratos Native sparse linear algebra
Utilities
Kratos API
Kratos Structural Mechanics API