HILA
Loading...
Searching...
No Matches
hila::global< T, custom > Class Template Reference

Global variable class within hila namespace. More...

#include <globals.h>

Detailed Description

template<typename T, typename custom = void>
class hila::global< T, custom >

Global variable class within hila namespace.

Special wrapper for "simple" types (elementary types, simple structs etc.). Implemented on gpus automatically using __constant__ memory. All global variables exist for the whole program lifetime.

Variable declaration:

Declaration is possible on top (file) level only, not inside functions!

Global variable class within hila namespace.
Definition globals.h:97

For example

Variable assingment:

globalvar.set(<value>);

Assignment is not possible inside loops Only "full" assignment is possible, not e.g. by struct records. Value must be convertible to the type of the global

Variable access

The value of the variable is obtained with .get() -method

globalvar.get();

.get() returns a const reference to the variable, it does no copying Variable can be used everywhere in the source file.

// at global file level
struct param_t { double a,b[2]; };
params.set( {1,2,3} );
// define some function
double myfunc(double dv) {
return cos( dv / params.get().a );
}
...
// inside main() or some other function - use helper struct to assign values
param_t tmp;
tmp.a = 3*M_PI;
tmp.b[0] = ....
tmp.b[1] = ...
params.set(tmp); // do the full struct assignment to global
...
Field<double> df;
onsites(ALL) {
df[X] = myfunc(X.x()) + params.get().b[0]/params.get().b[1];
}
hila::out0 << "Parameter a is " << params().a << '\n';
constexpr Parity ALL
bit pattern: 011
std::ostream out0
This writes output only from main process (node 0)

Additional information

"extern" and "static" can be used, if there are several source files, with the usual meaning:

extern hila::global<double> a; // variable a (of identical type) is defined
// in some other file
static hila::global<mytype> par; // par is invisible to other files

Declarations can be enclosed in namespaces:

namespace myglobals {
}
...
myglobals::a.set(3);
hila::out0 << "a has value " << myglobals::a.get() << '\n';

Variables cannot be initialized in declaration, because (possible) GPUs are not initialized.

Definition at line 97 of file globals.h.


The documentation for this class was generated from the following file: