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:95

For example

Variable assingment:

globalvar = <value>;

Assignment is not possible inside loops Only "full" assignment is possible, not e.g. by field records

Variable access

The value of the variable is obtained with function-like "()" call

globalvar();

Variable can be used everywhere in the source file.

// at global file level
struct param_t { double a,b[2]; };
// define some function
double myfunc(double dv) {
return cos( dv / params().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 = tmp; // do the full struct assignment to global
...
Field<double> df;
onsites(ALL) {
df[X] = myfunc(X.x()) + params().b[0]/params().b[1];
}
hila::out0 << "Parameter a is " << params().a << '\n';
Array< n, m, T > cos(Array< n, m, T > a)
Cosine.
Definition array.h:1089
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 = 3;
hila::out0 << "a has value " << myglobals::a() << '\n';

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

Definition at line 95 of file globals.h.


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