MRMD 0.4.0
Multi Resolution Molecular Dynamics
Loading...
Searching...
No Matches
Random.hpp
Go to the documentation of this file.
1// Copyright 2024 Sebastian Eibl
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <Kokkos_Random.hpp>
18
19#include "data/Atoms.hpp"
20#include "datatypes.hpp"
21
22namespace mrmd
23{
24namespace util
25{
26struct Random
27{
28 // The GeneratorPool
29 Kokkos::Random_XorShift1024_Pool<> randPool_;
30
31 Random() : randPool_(1234) {}
32
33 KOKKOS_INLINE_FUNCTION
34 real_t draw() const
35 {
36 // Get a random number state from the pool for the active thread
37 auto randGen = randPool_.get_state();
38
39 auto tmp = randGen.drand();
40
41 // Give the state back, which will allow another thread to acquire it
42 randPool_.free_state(randGen);
43
44 return tmp;
45 }
46};
47} // namespace util
48} // namespace mrmd
Definition BerendsenBarostat.cpp:18
double real_t
Definition datatypes.hpp:99
Definition Random.hpp:27
Random()
Definition Random.hpp:31
KOKKOS_INLINE_FUNCTION real_t draw() const
Definition Random.hpp:34
Kokkos::Random_XorShift1024_Pool randPool_
Definition Random.hpp:29