Astaroth  3.1
Scalable Multi-GPU Stencil Computations
Loading...
Searching...
No Matches
astaroth.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2014-2026, Johannes Pekkila, Touko Puro, Miikka Vaisala.
3
4 This file is part of Astaroth.
5
6 Astaroth is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Astaroth is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Astaroth. If not, see <http://www.gnu.org/licenses/>.
18*/
19#pragma once
20
21#ifndef _GNU_SOURCE
22#define _GNU_SOURCE
23#endif
24
25#include <stdint.h>
26#include <stdio.h>
27#include <string.h>
28
29#include "ac_mpi.h"
30#include "acc_runtime.h"
31#include "acreal.h"
32#include "astaroth_analysis.h"
33#include "astaroth_base.h"
34#include "astaroth_device.h"
35// The device headers are not needed for interfacing with Astaroth
37#include "astaroth_grid.h"
38#include "astaroth_helpers.h"
39#include "astaroth_legacy.h"
40#include "astaroth_logging.h"
41#include "astaroth_node.h"
43#include "builtin_enums.h"
44#include "errchk.h"
45#include "func_define.h"
46#include "host_datatypes.h"
47
48// clang-format off
49#include "user_defines.h"
50// clang-format on
51
52
54
55int3
56acDecompose(const uint64_t target, const AcMeshInfo info);
57int3
58acGetPid3D(const uint64_t pid, const int3 decomp, const AcMeshInfo info);
59int
60acGetPid(const int3 pid, const int3 decomp, const AcMeshInfo info);
61
62#include "get_vtxbufs_declares.h"
63
68
69static UNUSED AcCompInfo
70acInitCompInfo()
71{
72 AcCompInfo res;
73 // TP: initially nothing is loaded and if they are not loaded their values
74 // might as well be zero since then a default value is used for them
75 memset(&res, 0, sizeof(res));
76 return res;
77}
78
79static UNUSED AcMeshInfo
80acInitInfo()
81{
82 AcMeshInfo res;
83 // TP: this is useful for the following reasons:
84 // All enums are initialized by default to the first enum value
85 // All array ptrs are initialized to nulls
86 // All booleans are initialized to false
87 // All booleans about whether values are loaded are false
88 memset(&res, 0, sizeof(res));
89 // memset reads the second parameter as a byte even though it says int in
90 // the function declaration
91 // TP: for backwards compatibility set original datatypes to all ones as before
92 memset(&res.int_params, (uint8_t)0xFF, sizeof(res.int_params));
93 memset(&res.real_params, (uint8_t)0xFF, sizeof(res.real_params));
94 memset(&res.int3_params, (uint8_t)0xFF, sizeof(res.int3_params));
95 memset(&res.real3_params, (uint8_t)0xFF, sizeof(res.real3_params));
96 memset(&res.complex_params, (uint8_t)0xFF, sizeof(res.complex_params));
97
98#if AC_MPI_ENABLED
99 res.comm = (AcCommunicator*)malloc(sizeof(AcCommunicator));
100 res.comm->handle = MPI_COMM_NULL;
101#endif
102 res.run_consts = acInitCompInfo();
103 return res;
104}
105
106
107#include "ac_push_to_config_decl.h"
108
109
110static UNUSED AcMesh
111acInitMesh()
112{
113 AcMesh res;
114 for (size_t j = 0; j < NUM_VTXBUF_HANDLES; ++j) {
115 res.vertex_buffer[j] = NULL;
116 }
117 res.info = acInitInfo();
118 return res;
119}
120
121static const char*
122acGetDefaultConfig()
123{
124 // if (filepath == NULL) return NULL;
125
126 return AC_DEFAULT_CONFIG;
127 // return AC_SUCCESS;
128}
129
131
132#ifdef __cplusplus
133
134template <typename P, typename V>
135void
136acPushToConfig(AcMeshInfo& config, P param, V val)
137{
138 (void)param;
139 (void)val;
140 if constexpr(IsCompParam<P>())
141 {
142 config.run_consts.config[param] = val;
143 config.run_consts.is_loaded[param] = true;
144 }
145 else if constexpr(IsParam<P>())
146 {
147 config[param] = val;
148 config.is_loaded[param] = true;
149 }
150}
151
152static AcResult
153acUpdateDecompositionParams(AcMeshInfo* dst)
154{
155#if AC_MPI_ENABLED
156 int nprocs{};
157 int rank{};
158 ERRCHK_ALWAYS(dst->comm != NULL && dst->comm->handle != MPI_COMM_NULL);
159 MPI_Comm_size(dst->comm->handle,&nprocs);
160 MPI_Comm_rank(dst->comm->handle,&rank);
161 const int3 decomp = acDecompose(nprocs,*dst);
162 const int3 pid3d = acGetPid3D(rank,decomp,*dst);
163 acPushToConfig((*dst),AC_domain_coordinates,pid3d);
164 acPushToConfig((*dst),AC_domain_decomposition,decomp);
165 return AC_SUCCESS;
166#else
167 return AC_FAILURE;
168#endif
169}
170
171#endif
AcResult acLoadLibrary(const AcMeshInfo info)
AcResult acCloseLibrary()
int acGetPid(const int3 pid, const int3 decomp, const AcMeshInfo info)
int3 acGetPid3D(const uint64_t pid, const int3 decomp, const AcMeshInfo info)
int3 acDecompose(const uint64_t target, const AcMeshInfo info)
AcResult AcMeshInfo * config
Definition astaroth_utils.h:113
Brief info.
#define ERRCHK_ALWAYS(retval)
Definition errchk.h:95
#define UNUSED
Definition func_attributes.h:4
#define AC_BEGIN_C_DECLARATIONS
Definition func_define.h:14
#define AC_END_C_DECLARATIONS
Definition func_define.h:15
AcResult
Definition host_datatypes.h:10
@ AC_SUCCESS
Definition host_datatypes.h:10
@ AC_FAILURE
Definition host_datatypes.h:10
Definition ac_mpi.h:36
Definition acc_runtime.h:136
Definition acc_runtime.h:156
AcCompInfo run_consts
Definition acc_runtime.h:169
AcCommunicator * comm
Definition acc_runtime.h:168
Definition astaroth_base.h:41
AcReal * vertex_buffer[NUM_ALL_FIELDS]
Definition astaroth_base.h:42
AcMeshInfo info
Definition astaroth_base.h:44
static __device__ const int const int const AcRealArrayParam param
Definition user_kernel.h:129