OpenQMC API
Loading...
Searching...
No Matches
rank1.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright Contributors to the OpenQMC Project.
3
9
10#pragma once
11
12#include "gpu.h"
13#include "pcg.h"
14#include "permute.h"
15
16#include <cassert>
17#include <cstdint>
18
19namespace oqmc
20{
21
33OQMC_HOST_DEVICE constexpr std::uint32_t rotate(std::uint32_t value,
34 std::uint32_t distance)
35{
36 return value + distance;
37}
38
48OQMC_HOST_DEVICE constexpr std::uint32_t
49latticeReversedIndex(std::uint32_t index, int dimension)
50{
51 assert(dimension >= 0);
52 assert(dimension <= 3);
53
54 // Following Rank1 lattice numbers were taken from the orignal publication
55 // listed at the top of this file.
56
57 // clang-format off
58 constexpr int lattice[4] = {
59 1,
60 364981,
61 245389,
62 97823,
63 };
64 // clang-format on
65
66 return lattice[dimension] * index;
67}
68
80template <int Depth>
81OQMC_HOST_DEVICE constexpr void
82shuffledRotatedLattice(std::uint32_t index, std::uint32_t patternId,
83 std::uint32_t sample[Depth])
84{
85 static_assert(Depth >= 1, "Pattern depth is greater or equal to one.");
86 static_assert(Depth <= 4, "Pattern depth is less or equal to four.");
87
88 index = reverseAndShuffle(index, pcg::output(patternId));
89
90 for(int i = 0; i < Depth; ++i)
91 {
92 sample[i] = latticeReversedIndex(index, i);
93 sample[i] = rotate(sample[i], pcg::rng(patternId));
94 }
95}
96
97} // namespace oqmc
#define OQMC_HOST_DEVICE
Definition gpu.h:13
constexpr std::uint32_t output(std::uint32_t state)
Output permutation function.
Definition pcg.h:96
constexpr std::uint32_t rng(std::uint32_t &state)
Compute a random number from the PRNG sequence.
Definition pcg.h:162
constexpr std::uint32_t reverseAndShuffle(std::uint32_t value, std::uint32_t seed)
Reverse input bits and shuffle order.
Definition permute.h:54
EncodeKey decodeBits16(std::uint16_t value)
Decode a value back into a key.
Definition encode.h:81
Definition bntables.h:21
constexpr void shuffledRotatedLattice(std::uint32_t index, std::uint32_t patternId, std::uint32_t sample[Depth])
Compute a randomised rank 1 lattice value.
Definition rank1.h:82
constexpr std::uint32_t rotate(std::uint32_t value, std::uint32_t distance)
Rotate an integer a given distance.
Definition rank1.h:33
constexpr std::uint32_t latticeReversedIndex(std::uint32_t index, int dimension)
Compute a rank 1 lattice value at an index with reversed bits.
Definition rank1.h:49