-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparams_GPU.cu
More file actions
61 lines (57 loc) · 1.43 KB
/
params_GPU.cu
File metadata and controls
61 lines (57 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "params_GPU.cuh"
__global__ void init(int *matrix, int mat_size, int seed)
{
int i = blockIdx.x * blockDim.x + threadIdx.x;
int j = blockIdx.y * blockDim.y + threadIdx.y;
if (i < mat_size && j < mat_size)
{
int idx = i * mat_size + j;
curandState state;
curand_init(seed, idx, 0, &state);
float value = curand_uniform(&state);
if (value > 0.5)
{
matrix[idx] = 1;
}
else
{
matrix[idx] = -1;
}
}
}
// a function to print the final state of the matrix
__host__ void print_state(int *mat, int mat_size)
{
// print matrix
for (int i = 0; i < mat_size; ++i)
{
for (int j = 0; j < mat_size; ++j)
{
if (mat[i * mat_size + j] == 1)
{
std::cout << "+ ";
}
else
{
std::cout << "- ";
}
}
std::cout << "\n";
}
std::cout << "\n";
}
// a function to get the mean energy on the lattice
__host__ void mean_energy(int *mat, int mat_size)
{
double sum = 0.0;
for (int i = 0; i < mat_size; i++)
{
for (int j = 0; j < mat_size; j++)
{
sum += mat[i * mat_size + j];
}
}
int total_elements = mat_size * mat_size;
double mean = sum / (total_elements);
std::cout << "Mean of " << total_elements << " samples: " << mean << std::endl;
}