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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
|
<center><a href="https://gitlab.com/petsc/petsc/-/blob/966382dc56242773704ef5f5cee7aa2db3ebc577/include/petscdevice.h">Actual source code: petscdevice.h</a></center><br>
<html>
<head>
<title></title>
<meta name="generator" content="c2html 0.9.6">
<meta name="date" content="2025-04-30T18:14:50+00:00">
</head>
<body bgcolor="#FFFFFF">
<pre width=80>
<a name="line1"> 1: </a><font color="#A020F0">#pragma once</font>
<a name="line3"> 3: </a>#include <A href="../include/petscdevicetypes.h.html"><petscdevicetypes.h></A>
<a name="line4"> 4: </a>#include <A href="../include/petscviewertypes.h.html"><petscviewertypes.h></A>
<a name="line6"> 6: </a><font color="#A020F0">#if PETSC_CPP_VERSION >= 11 // C++11</font>
<a name="line7"> 7: </a><strong><font color="#228B22"> #define PETSC_DEVICE_ALIGNOF(...) alignof(decltype(__VA_ARGS__))</font></strong>
<a name="line8"> 8: </a><font color="#A020F0">#elif PETSC_C_VERSION >= 11 // C11</font>
<a name="line9"> 9: </a><font color="#A020F0"> #ifdef __GNUC__</font>
<a name="line10"> 10: </a><strong><font color="#228B22"> #define PETSC_DEVICE_ALIGNOF(...) _Alignof(__typeof__(__VA_ARGS__))</font></strong>
<a name="line11"> 11: </a><font color="#A020F0"> #else</font>
<a name="line12"> 12: </a><font color="#A020F0"> #include <stddef.h> // max_align_t</font>
<a name="line13"> 13: </a> <font color="#B22222">// Note we cannot just do _Alignof(expression) since clang warns that "'_Alignof' applied to an</font>
<a name="line14"> 14: </a> <font color="#B22222">// expression is a GNU extension", so we just default to max_align_t which is ultra safe</font>
<a name="line15"> 15: </a><strong><font color="#228B22"> #define PETSC_DEVICE_ALIGNOF(...) _Alignof(max_align_t)</font></strong>
<a name="line16"> 16: </a><font color="#A020F0"> #endif // __GNUC__</font>
<a name="line17"> 17: </a><font color="#A020F0">#else</font>
<a name="line18"> 18: </a><strong><font color="#228B22"> #define PETSC_DEVICE_ALIGNOF(...) PETSC_MEMALIGN</font></strong>
<a name="line19"> 19: </a><font color="#A020F0">#endif</font>
<a name="line21"> 21: </a><font color="#B22222">/* MANSEC = Sys */</font>
<a name="line22"> 22: </a><font color="#B22222">/* SUBMANSEC = Device */</font>
<a name="line24"> 24: </a><font color="#B22222">// REVIEW ME: this should probably go somewhere better, configure-time?</font>
<a name="line25"> 25: </a><strong><font color="#228B22">#define PETSC_HAVE_HOST 1</font></strong>
<a name="line27"> 27: </a><font color="#B22222">/* logging support */</font>
<a name="line28"> 28: </a>PETSC_EXTERN <a href="../manualpages/Sys/PetscClassId.html">PetscClassId</a> PETSC_DEVICE_CLASSID;
<a name="line29"> 29: </a>PETSC_EXTERN <a href="../manualpages/Sys/PetscClassId.html">PetscClassId</a> PETSC_DEVICE_CONTEXT_CLASSID;
<a name="line31"> 31: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Sys/PetscDeviceInitializePackage.html">PetscDeviceInitializePackage</a>(void)</font></strong>;
<a name="line32"> 32: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Sys/PetscDeviceFinalizePackage.html">PetscDeviceFinalizePackage</a>(void)</font></strong>;
<a name="line33"> 33: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Sys/PetscGetMemType.html">PetscGetMemType</a>(const void *, <a href="../manualpages/Sys/PetscMemType.html">PetscMemType</a> *)</font></strong>;
<a name="line35"> 35: </a><font color="#B22222">/* <a href="../manualpages/Sys/PetscDevice.html">PetscDevice</a> */</font>
<a name="line36"> 36: </a><font color="#A020F0">#if <a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>(HAVE_CXX)</font>
<a name="line37"> 37: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceCreate.html">PetscDeviceCreate</a>(<a href="../manualpages/Sys/PetscDeviceType.html">PetscDeviceType</a>, <a href="../manualpages/Sys/PetscInt.html">PetscInt</a>, <a href="../manualpages/Sys/PetscDevice.html">PetscDevice</a> *)</font></strong>;
<a name="line38"> 38: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceDestroy.html">PetscDeviceDestroy</a>(<a href="../manualpages/Sys/PetscDevice.html">PetscDevice</a> *)</font></strong>;
<a name="line39"> 39: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceConfigure.html">PetscDeviceConfigure</a>(<a href="../manualpages/Sys/PetscDevice.html">PetscDevice</a>)</font></strong>;
<a name="line40"> 40: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceView.html">PetscDeviceView</a>(<a href="../manualpages/Sys/PetscDevice.html">PetscDevice</a>, <a href="../manualpages/Viewer/PetscViewer.html">PetscViewer</a>)</font></strong>;
<a name="line41"> 41: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceGetType.html">PetscDeviceGetType</a>(<a href="../manualpages/Sys/PetscDevice.html">PetscDevice</a>, <a href="../manualpages/Sys/PetscDeviceType.html">PetscDeviceType</a> *)</font></strong>;
<a name="line42"> 42: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceGetDeviceId.html">PetscDeviceGetDeviceId</a>(<a href="../manualpages/Sys/PetscDevice.html">PetscDevice</a>, <a href="../manualpages/Sys/PetscInt.html">PetscInt</a> *)</font></strong>;
<a name="line43"> 43: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscDeviceType.html">PetscDeviceType</a> <a href="../manualpages/Device/PETSC_DEVICE_DEFAULT.html">PETSC_DEVICE_DEFAULT</a>(void)</font></strong>;
<a name="line44"> 44: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceSetDefaultDeviceType.html">PetscDeviceSetDefaultDeviceType</a>(<a href="../manualpages/Sys/PetscDeviceType.html">PetscDeviceType</a>)</font></strong>;
<a name="line45"> 45: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceInitialize.html">PetscDeviceInitialize</a>(<a href="../manualpages/Sys/PetscDeviceType.html">PetscDeviceType</a>)</font></strong>;
<a name="line46"> 46: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscBool.html">PetscBool</a> <a href="../manualpages/Device/PetscDeviceInitialized.html">PetscDeviceInitialized</a>(<a href="../manualpages/Sys/PetscDeviceType.html">PetscDeviceType</a>)</font></strong>;
<a name="line47"> 47: </a><font color="#A020F0">#else</font>
<a name="line48"> 48: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceCreate.html">PetscDeviceCreate</a>(<a href="../manualpages/Sys/PetscDeviceType.html">PetscDeviceType</a>, <a href="../manualpages/Sys/PetscInt.html">PetscInt</a>, dev) (*(dev) = <a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>)</font></strong>
<a name="line49"> 49: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceDestroy.html">PetscDeviceDestroy</a>(dev) (*(dev) = <a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>)</font></strong>
<a name="line50"> 50: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceConfigure.html">PetscDeviceConfigure</a>(<a href="../manualpages/Sys/PetscDevice.html">PetscDevice</a>) <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a></font></strong>
<a name="line51"> 51: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceView.html">PetscDeviceView</a>(<a href="../manualpages/Sys/PetscDevice.html">PetscDevice</a>, <a href="../manualpages/Viewer/PetscViewer.html">PetscViewer</a>) <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a></font></strong>
<a name="line52"> 52: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceGetType.html">PetscDeviceGetType</a>(<a href="../manualpages/Sys/PetscDevice.html">PetscDevice</a>, type) (*(type) = <a href="../manualpages/Device/PETSC_DEVICE_DEFAULT.html">PETSC_DEVICE_DEFAULT</a>(), <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>)</font></strong>
<a name="line53"> 53: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceGetDeviceId.html">PetscDeviceGetDeviceId</a>(<a href="../manualpages/Sys/PetscDevice.html">PetscDevice</a>, id) (*(id) = 0, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>)</font></strong>
<a name="line54"> 54: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PETSC_DEVICE_DEFAULT.html">PETSC_DEVICE_DEFAULT</a>() <a href="../manualpages/Sys/PetscDeviceType.html">PETSC_DEVICE_HOST</a></font></strong>
<a name="line55"> 55: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceSetDefaultDeviceType.html">PetscDeviceSetDefaultDeviceType</a>(<a href="../manualpages/Sys/PetscDeviceType.html">PetscDeviceType</a>) <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a></font></strong>
<a name="line56"> 56: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceInitialize.html">PetscDeviceInitialize</a>(<a href="../manualpages/Sys/PetscDeviceType.html">PetscDeviceType</a>) <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a></font></strong>
<a name="line57"> 57: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceInitialized.html">PetscDeviceInitialized</a>(dtype) ((dtype) == <a href="../manualpages/Sys/PetscDeviceType.html">PETSC_DEVICE_HOST</a>)</font></strong>
<a name="line58"> 58: </a><font color="#A020F0">#endif </font><font color="#B22222">/* <a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>(HAVE_CXX) */</font><font color="#A020F0"></font>
<a name="line60"> 60: </a><font color="#B22222">/* <a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a> */</font>
<a name="line61"> 61: </a><font color="#A020F0">#if <a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>(HAVE_CXX)</font>
<a name="line62"> 62: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceContextCreate.html">PetscDeviceContextCreate</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a> *)</font></strong>;
<a name="line63"> 63: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceContextDestroy.html">PetscDeviceContextDestroy</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a> *)</font></strong>;
<a name="line64"> 64: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceContextSetStreamType.html">PetscDeviceContextSetStreamType</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, <a href="../manualpages/Sys/PetscStreamType.html">PetscStreamType</a>)</font></strong>;
<a name="line65"> 65: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceContextGetStreamType.html">PetscDeviceContextGetStreamType</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, <a href="../manualpages/Sys/PetscStreamType.html">PetscStreamType</a> *)</font></strong>;
<a name="line66"> 66: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceContextSetDevice.html">PetscDeviceContextSetDevice</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, <a href="../manualpages/Sys/PetscDevice.html">PetscDevice</a>)</font></strong>;
<a name="line67"> 67: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceContextGetDevice.html">PetscDeviceContextGetDevice</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, <a href="../manualpages/Sys/PetscDevice.html">PetscDevice</a> *)</font></strong>;
<a name="line68"> 68: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceContextGetDeviceType.html">PetscDeviceContextGetDeviceType</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, <a href="../manualpages/Sys/PetscDeviceType.html">PetscDeviceType</a> *)</font></strong>;
<a name="line69"> 69: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceContextSetUp.html">PetscDeviceContextSetUp</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>)</font></strong>;
<a name="line70"> 70: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceContextDuplicate.html">PetscDeviceContextDuplicate</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, <a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a> *)</font></strong>;
<a name="line71"> 71: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceContextQueryIdle.html">PetscDeviceContextQueryIdle</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, <a href="../manualpages/Sys/PetscBool.html">PetscBool</a> *)</font></strong>;
<a name="line72"> 72: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceContextWaitForContext.html">PetscDeviceContextWaitForContext</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, <a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>)</font></strong>;
<a name="line73"> 73: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceContextForkWithStreamType.html">PetscDeviceContextForkWithStreamType</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, <a href="../manualpages/Sys/PetscStreamType.html">PetscStreamType</a>, <a href="../manualpages/Sys/PetscInt.html">PetscInt</a>, <a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a> **)</font></strong>;
<a name="line74"> 74: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceContextFork.html">PetscDeviceContextFork</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, <a href="../manualpages/Sys/PetscInt.html">PetscInt</a>, <a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a> **)</font></strong>;
<a name="line75"> 75: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceContextJoin.html">PetscDeviceContextJoin</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, <a href="../manualpages/Sys/PetscInt.html">PetscInt</a>, <a href="../manualpages/Sys/PetscDeviceContextJoinMode.html">PetscDeviceContextJoinMode</a>, <a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a> **)</font></strong>;
<a name="line76"> 76: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceContextSynchronize.html">PetscDeviceContextSynchronize</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>)</font></strong>;
<a name="line77"> 77: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceContextSetFromOptions.html">PetscDeviceContextSetFromOptions</a>(<a href="../manualpages/Sys/MPI_Comm.html">MPI_Comm</a>, <a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>)</font></strong>;
<a name="line78"> 78: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceContextView.html">PetscDeviceContextView</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, <a href="../manualpages/Viewer/PetscViewer.html">PetscViewer</a>)</font></strong>;
<a name="line79"> 79: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceContextViewFromOptions.html">PetscDeviceContextViewFromOptions</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, <a href="../manualpages/Sys/PetscObject.html">PetscObject</a>, const char[])</font></strong>;
<a name="line80"> 80: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceContextGetCurrentContext.html">PetscDeviceContextGetCurrentContext</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a> *)</font></strong>;
<a name="line81"> 81: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceContextSetCurrentContext.html">PetscDeviceContextSetCurrentContext</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>)</font></strong>;
<a name="line82"> 82: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceContextGetStreamHandle.html">PetscDeviceContextGetStreamHandle</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, void **)</font></strong>;
<a name="line83"> 83: </a><font color="#A020F0">#else</font>
<a name="line84"> 84: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceContextCreate.html">PetscDeviceContextCreate</a>(dctx) (*(dctx) = <a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>)</font></strong>
<a name="line85"> 85: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceContextDestroy.html">PetscDeviceContextDestroy</a>(dctx) (*(dctx) = <a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>)</font></strong>
<a name="line86"> 86: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceContextSetStreamType.html">PetscDeviceContextSetStreamType</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, <a href="../manualpages/Sys/PetscStreamType.html">PetscStreamType</a>) <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a></font></strong>
<a name="line87"> 87: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceContextGetStreamType.html">PetscDeviceContextGetStreamType</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, type) (*(type) = <a href="../manualpages/Sys/PetscStreamType.html">PETSC_STREAM_DEFAULT</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>)</font></strong>
<a name="line88"> 88: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceContextSetDevice.html">PetscDeviceContextSetDevice</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, <a href="../manualpages/Sys/PetscDevice.html">PetscDevice</a>) <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a></font></strong>
<a name="line89"> 89: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceContextGetDevice.html">PetscDeviceContextGetDevice</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, device) (*(device) = <a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>)</font></strong>
<a name="line90"> 90: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceContextGetDeviceType.html">PetscDeviceContextGetDeviceType</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, type) (*(type) = <a href="../manualpages/Device/PETSC_DEVICE_DEFAULT.html">PETSC_DEVICE_DEFAULT</a>(), <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>)</font></strong>
<a name="line91"> 91: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceContextSetUp.html">PetscDeviceContextSetUp</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>) <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a></font></strong>
<a name="line92"> 92: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceContextDuplicate.html">PetscDeviceContextDuplicate</a>(PetscDeviceContextl, PetscDeviceContextr) (*(PetscDeviceContextr) = <a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>)</font></strong>
<a name="line93"> 93: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceContextQueryIdle.html">PetscDeviceContextQueryIdle</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, idle) (*(idle) = <a href="../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>)</font></strong>
<a name="line94"> 94: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceContextWaitForContext.html">PetscDeviceContextWaitForContext</a>(PetscDeviceContextl, PetscDeviceContextr) <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a></font></strong>
<a name="line95"> 95: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceContextForkWithStreamType.html">PetscDeviceContextForkWithStreamType</a>(PetscDeviceContextp, <a href="../manualpages/Sys/PetscStreamType.html">PetscStreamType</a>, <a href="../manualpages/Sys/PetscInt.html">PetscInt</a>, PetscDeviceContextc) (*(PetscDeviceContextc) = <a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>)</font></strong>
<a name="line96"> 96: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceContextFork.html">PetscDeviceContextFork</a>(PetscDeviceContextp, <a href="../manualpages/Sys/PetscInt.html">PetscInt</a>, PetscDeviceContextc) (*(PetscDeviceContextc) = <a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>)</font></strong>
<a name="line97"> 97: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceContextJoin.html">PetscDeviceContextJoin</a>(PetscDeviceContextp, <a href="../manualpages/Sys/PetscInt.html">PetscInt</a>, <a href="../manualpages/Sys/PetscDeviceContextJoinMode.html">PetscDeviceContextJoinMode</a>, PetscDeviceContextc) (*(PetscDeviceContextc) = <a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>)</font></strong>
<a name="line98"> 98: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceContextSynchronize.html">PetscDeviceContextSynchronize</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>) <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a></font></strong>
<a name="line99"> 99: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceContextSetFromOptions.html">PetscDeviceContextSetFromOptions</a>(<a href="../manualpages/Sys/MPI_Comm.html">MPI_Comm</a>, <a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>) <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a></font></strong>
<a name="line100">100: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceContextView.html">PetscDeviceContextView</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, <a href="../manualpages/Viewer/PetscViewer.html">PetscViewer</a>) <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a></font></strong>
<a name="line101">101: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceContextViewFromOptions.html">PetscDeviceContextViewFromOptions</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, <a href="../manualpages/Sys/PetscObject.html">PetscObject</a>, <a href="../manualpages/Viewer/PetscViewer.html">PetscViewer</a>) <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a></font></strong>
<a name="line102">102: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceContextGetCurrentContext.html">PetscDeviceContextGetCurrentContext</a>(dctx) (*(dctx) = <a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>)</font></strong>
<a name="line103">103: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceContextSetCurrentContext.html">PetscDeviceContextSetCurrentContext</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>) <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a></font></strong>
<a name="line104">104: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceContextGetStreamHandle.html">PetscDeviceContextGetStreamHandle</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, handle) (*(handle) = <a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>)</font></strong>
<a name="line105">105: </a><font color="#A020F0">#endif </font><font color="#B22222">/* <a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>(HAVE_CXX) */</font><font color="#A020F0"></font>
<a name="line107">107: </a><font color="#B22222">/* memory */</font>
<a name="line108">108: </a><font color="#A020F0">#if <a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>(HAVE_CXX)</font>
<a name="line109">109: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PetscDeviceAllocate_Private(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, <a href="../manualpages/Sys/PetscBool.html">PetscBool</a>, <a href="../manualpages/Sys/PetscMemType.html">PetscMemType</a>, size_t, size_t, void **PETSC_RESTRICT)</font></strong>;
<a name="line110">110: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> PetscDeviceDeallocate_Private(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, void *PETSC_RESTRICT)</font></strong>;
<a name="line111">111: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceMemcpy.html">PetscDeviceMemcpy</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, void *PETSC_RESTRICT, const void *PETSC_RESTRICT, size_t)</font></strong>;
<a name="line112">112: </a><strong><font color="#4169E1">PETSC_EXTERN <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceMemset.html">PetscDeviceMemset</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, void *PETSC_RESTRICT, <a href="../manualpages/Sys/PetscInt.html">PetscInt</a>, size_t)</font></strong>;
<a name="line113">113: </a><font color="#A020F0">#else</font>
<a name="line114">114: </a><font color="#A020F0"> #include <string.h> // memset()</font>
<a name="line115">115: </a><strong><font color="#228B22"> #define PetscDeviceAllocate_Private(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, clear, <a href="../manualpages/Sys/PetscMemType.html">PetscMemType</a>, size, alignment, ptr) <a href="../manualpages/Sys/PetscMallocA.html">PetscMallocA</a>(1, (clear), __LINE__, PETSC_FUNCTION_NAME, __FILE__, (size), (ptr))</font></strong>
<a name="line116">116: </a><strong><font color="#228B22"> #define PetscDeviceDeallocate_Private(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, ptr) <a href="../manualpages/Sys/PetscFree.html">PetscFree</a>(ptr)</font></strong>
<a name="line117">117: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceMemcpy.html">PetscDeviceMemcpy</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, dest, src, size) <a href="../manualpages/Sys/PetscMemcpy.html">PetscMemcpy</a>((dest), (src), (size))</font></strong>
<a name="line118">118: </a><strong><font color="#228B22"> #define <a href="../manualpages/Device/PetscDeviceMemset.html">PetscDeviceMemset</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>, ptr, v, size) ((void)memset((ptr), (unsigned char)(v), (size)), <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>)</font></strong>
<a name="line119">119: </a><font color="#A020F0">#endif </font><font color="#B22222">/* <a href="../manualpages/Sys/PetscDefined.html">PetscDefined</a>(HAVE_CXX) */</font><font color="#A020F0"></font>
<a name="line121">121: </a><font color="#B22222">/*MC</font>
<a name="line122">122: </a><font color="#B22222"> <a href="../manualpages/Device/PetscDeviceMalloc.html">PetscDeviceMalloc</a> - Allocate device-aware memory</font>
<a name="line124">124: </a><font color="#B22222"> Synopsis:</font>
<a name="line125">125: </a>#include <A href="../include/petscdevice.h.html"><petscdevice.h></A>
<a name="line126">126: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceMalloc.html">PetscDeviceMalloc</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a> dctx, <a href="../manualpages/Sys/PetscMemType.html">PetscMemType</a> mtype, size_t n, Type **ptr)</font>
<a name="line128">128: </a><font color="#B22222"> Not Collective, Asynchronous, Auto-dependency aware</font>
<a name="line130">130: </a><font color="#B22222"> Input Parameters:</font>
<a name="line131">131: </a><font color="#B22222">+ dctx - The `<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>` used to allocate the memory</font>
<a name="line132">132: </a><font color="#B22222">. mtype - The type of memory to allocate</font>
<a name="line133">133: </a><font color="#B22222">- n - The amount (in elements) to allocate</font>
<a name="line135">135: </a><font color="#B22222"> Output Parameter:</font>
<a name="line136">136: </a><font color="#B22222">. ptr - The pointer to store the result in</font>
<a name="line138">138: </a><font color="#B22222"> Level: beginner</font>
<a name="line140">140: </a><font color="#B22222"> Notes:</font>
<a name="line141">141: </a><font color="#B22222"> Memory allocated with this function must be freed with `<a href="../manualpages/Device/PetscDeviceFree.html">PetscDeviceFree</a>()`.</font>
<a name="line143">143: </a><font color="#B22222"> If `n` is zero, then `ptr` is set to `<a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a>`.</font>
<a name="line145">145: </a><font color="#B22222"> This routine falls back to using `<a href="../manualpages/Sys/PetscMalloc1.html">PetscMalloc1</a>()` if PETSc was not configured with device</font>
<a name="line146">146: </a><font color="#B22222"> support. The user should note that `mtype` is ignored in this case, as `<a href="../manualpages/Sys/PetscMalloc1.html">PetscMalloc1</a>()`</font>
<a name="line147">147: </a><font color="#B22222"> allocates only host memory.</font>
<a name="line149">149: </a><font color="#B22222"> This routine uses the `sizeof()` of the memory type requested to determine the total memory</font>
<a name="line150">150: </a><font color="#B22222"> to be allocated, therefore you should not multiply the number of elements requested by the</font>
<a name="line151">151: </a><font color="#B22222"> `sizeof()` the type\:</font>
<a name="line153">153: </a><font color="#B22222">.vb</font>
<a name="line154">154: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscInt.html">PetscInt</a> *arr;</font>
<a name="line156">156: </a><font color="#B22222"> // correct</font>
<a name="line157">157: </a><font color="#B22222"> <a href="../manualpages/Device/PetscDeviceMalloc.html">PetscDeviceMalloc</a>(dctx,<a href="../manualpages/Sys/PetscMemType.html">PETSC_MEMTYPE_DEVICE</a>,n,&arr);</font>
<a name="line159">159: </a><font color="#B22222"> // incorrect</font>
<a name="line160">160: </a><font color="#B22222"> <a href="../manualpages/Device/PetscDeviceMalloc.html">PetscDeviceMalloc</a>(dctx,<a href="../manualpages/Sys/PetscMemType.html">PETSC_MEMTYPE_DEVICE</a>,n*sizeof(*arr),&arr);</font>
<a name="line161">161: </a><font color="#B22222">.ve</font>
<a name="line163">163: </a><font color="#B22222"> Note result stored `ptr` is immediately valid and the user may freely inspect or manipulate</font>
<a name="line164">164: </a><font color="#B22222"> its value on function return, i.e.\:</font>
<a name="line166">166: </a><font color="#B22222">.vb</font>
<a name="line167">167: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscInt.html">PetscInt</a> *ptr;</font>
<a name="line169">169: </a><font color="#B22222"> <a href="../manualpages/Device/PetscDeviceMalloc.html">PetscDeviceMalloc</a>(dctx, <a href="../manualpages/Sys/PetscMemType.html">PETSC_MEMTYPE_DEVICE</a>, 20, &ptr);</font>
<a name="line171">171: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscInt.html">PetscInt</a> *sub_ptr = ptr + 10; // OK, no need to synchronize</font>
<a name="line173">173: </a><font color="#B22222"> ptr[0] = 10; // ERROR, directly accessing contents of ptr is undefined until synchronization</font>
<a name="line174">174: </a><font color="#B22222">.ve</font>
<a name="line176">176: </a><font color="#B22222"> DAG representation:</font>
<a name="line177">177: </a><font color="#B22222">.vb</font>
<a name="line178">178: </a><font color="#B22222"> time -></font>
<a name="line180">180: </a><font color="#B22222"> -> dctx - |= CALL =| -\- dctx --></font>
<a name="line181">181: </a><font color="#B22222"> \- ptr -></font>
<a name="line182">182: </a><font color="#B22222">.ve</font>
<a name="line184">184: </a><font color="#B22222">.N ASYNC_API</font>
<a name="line186">186: </a><font color="#B22222">.seealso: `<a href="../manualpages/Device/PetscDeviceFree.html">PetscDeviceFree</a>()`, `<a href="../manualpages/Device/PetscDeviceCalloc.html">PetscDeviceCalloc</a>()`, `<a href="../manualpages/Device/PetscDeviceArrayCopy.html">PetscDeviceArrayCopy</a>()`,</font>
<a name="line187">187: </a><font color="#B22222">`<a href="../manualpages/Device/PetscDeviceArrayZero.html">PetscDeviceArrayZero</a>()`</font>
<a name="line188">188: </a><font color="#B22222">M*/</font>
<a name="line189">189: </a><strong><font color="#228B22">#define <a href="../manualpages/Device/PetscDeviceMalloc.html">PetscDeviceMalloc</a>(dctx, mtype, n, ptr) PetscDeviceAllocate_Private((dctx), <a href="../manualpages/Sys/PETSC_FALSE.html">PETSC_FALSE</a>, (mtype), (size_t)(n) * sizeof(**(ptr)), PETSC_DEVICE_ALIGNOF(**(ptr)), (void **)(ptr))</font></strong>
<a name="line191">191: </a><font color="#B22222">/*MC</font>
<a name="line192">192: </a><font color="#B22222"> <a href="../manualpages/Device/PetscDeviceCalloc.html">PetscDeviceCalloc</a> - Allocate zeroed device-aware memory</font>
<a name="line194">194: </a><font color="#B22222"> Synopsis:</font>
<a name="line195">195: </a>#include <A href="../include/petscdevice.h.html"><petscdevice.h></A>
<a name="line196">196: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceCalloc.html">PetscDeviceCalloc</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a> dctx, <a href="../manualpages/Sys/PetscMemType.html">PetscMemType</a> mtype, size_t n, Type **ptr)</font>
<a name="line198">198: </a><font color="#B22222"> Not Collective, Asynchronous, Auto-dependency aware</font>
<a name="line200">200: </a><font color="#B22222"> Input Parameters:</font>
<a name="line201">201: </a><font color="#B22222">+ dctx - The `<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>` used to allocate the memory</font>
<a name="line202">202: </a><font color="#B22222">. mtype - The type of memory to allocate</font>
<a name="line203">203: </a><font color="#B22222">- n - The amount (in elements) to allocate</font>
<a name="line205">205: </a><font color="#B22222"> Output Parameter:</font>
<a name="line206">206: </a><font color="#B22222">. ptr - The pointer to store the result in</font>
<a name="line208">208: </a><font color="#B22222"> Level: beginner</font>
<a name="line210">210: </a><font color="#B22222"> Notes:</font>
<a name="line211">211: </a><font color="#B22222"> Has identical usage to `<a href="../manualpages/Device/PetscDeviceMalloc.html">PetscDeviceMalloc</a>()` except that the memory is zeroed before it is</font>
<a name="line212">212: </a><font color="#B22222"> returned. See `<a href="../manualpages/Device/PetscDeviceMalloc.html">PetscDeviceMalloc</a>()` for further discussion.</font>
<a name="line214">214: </a><font color="#B22222"> This routine falls back to using `<a href="../manualpages/Sys/PetscCalloc1.html">PetscCalloc1</a>()` if PETSc was not configured with device</font>
<a name="line215">215: </a><font color="#B22222"> support. The user should note that `mtype` is ignored in this case, as `<a href="../manualpages/Sys/PetscCalloc1.html">PetscCalloc1</a>()`</font>
<a name="line216">216: </a><font color="#B22222"> allocates only host memory.</font>
<a name="line218">218: </a><font color="#B22222">.N ASYNC_API</font>
<a name="line220">220: </a><font color="#B22222">.seealso: `<a href="../manualpages/Device/PetscDeviceFree.html">PetscDeviceFree</a>()`, `<a href="../manualpages/Device/PetscDeviceMalloc.html">PetscDeviceMalloc</a>()`, `<a href="../manualpages/Device/PetscDeviceArrayCopy.html">PetscDeviceArrayCopy</a>()`,</font>
<a name="line221">221: </a><font color="#B22222">`<a href="../manualpages/Device/PetscDeviceArrayZero.html">PetscDeviceArrayZero</a>()`</font>
<a name="line222">222: </a><font color="#B22222">M*/</font>
<a name="line223">223: </a><strong><font color="#228B22">#define <a href="../manualpages/Device/PetscDeviceCalloc.html">PetscDeviceCalloc</a>(dctx, mtype, n, ptr) PetscDeviceAllocate_Private((dctx), <a href="../manualpages/Sys/PETSC_TRUE.html">PETSC_TRUE</a>, (mtype), (size_t)(n) * sizeof(**(ptr)), PETSC_DEVICE_ALIGNOF(**(ptr)), (void **)(ptr))</font></strong>
<a name="line225">225: </a><font color="#B22222">/*MC</font>
<a name="line226">226: </a><font color="#B22222"> <a href="../manualpages/Device/PetscDeviceFree.html">PetscDeviceFree</a> - Free device-aware memory obtained with `<a href="../manualpages/Device/PetscDeviceMalloc.html">PetscDeviceMalloc</a>()` or `<a href="../manualpages/Device/PetscDeviceCalloc.html">PetscDeviceCalloc</a>()`</font>
<a name="line228">228: </a><font color="#B22222"> Synopsis:</font>
<a name="line229">229: </a>#include <A href="../include/petscdevice.h.html"><petscdevice.h></A>
<a name="line230">230: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceFree.html">PetscDeviceFree</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a> dctx, void *ptr)</font>
<a name="line232">232: </a><font color="#B22222"> Not Collective, Asynchronous, Auto-dependency aware</font>
<a name="line234">234: </a><font color="#B22222"> Input Parameters:</font>
<a name="line235">235: </a><font color="#B22222">+ dctx - The `<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>` used to free the memory</font>
<a name="line236">236: </a><font color="#B22222">- ptr - The pointer to free, may be `NULL`</font>
<a name="line238">238: </a><font color="#B22222"> Level: beginner</font>
<a name="line240">240: </a><font color="#B22222"> Notes:</font>
<a name="line241">241: </a><font color="#B22222"> `ptr` is set to `<a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a>` on successful deallocation.</font>
<a name="line243">243: </a><font color="#B22222"> `ptr` must have been allocated using `<a href="../manualpages/Device/PetscDeviceMalloc.html">PetscDeviceMalloc</a>()`, `<a href="../manualpages/Device/PetscDeviceCalloc.html">PetscDeviceCalloc</a>()` not `<a href="../manualpages/Sys/PetscMalloc.html">PetscMalloc</a>()` or related routines</font>
<a name="line245">245: </a><font color="#B22222"> This routine falls back to using `<a href="../manualpages/Sys/PetscFree.html">PetscFree</a>()` if PETSc was not configured with device</font>
<a name="line246">246: </a><font color="#B22222"> support. The user should note that `<a href="../manualpages/Sys/PetscFree.html">PetscFree</a>()` frees only host memory.</font>
<a name="line248">248: </a><font color="#B22222"> DAG representation:</font>
<a name="line249">249: </a><font color="#B22222">.vb</font>
<a name="line250">250: </a><font color="#B22222"> time -></font>
<a name="line252">252: </a><font color="#B22222"> -> dctx -/- |= CALL =| - dctx -></font>
<a name="line253">253: </a><font color="#B22222"> -> ptr -/</font>
<a name="line254">254: </a><font color="#B22222">.ve</font>
<a name="line256">256: </a><font color="#B22222">.N ASYNC_API</font>
<a name="line258">258: </a><font color="#B22222">.seealso: `<a href="../manualpages/Device/PetscDeviceMalloc.html">PetscDeviceMalloc</a>()`, `<a href="../manualpages/Device/PetscDeviceCalloc.html">PetscDeviceCalloc</a>()`</font>
<a name="line259">259: </a><font color="#B22222">M*/</font>
<a name="line260">260: </a><strong><font color="#228B22">#define <a href="../manualpages/Device/PetscDeviceFree.html">PetscDeviceFree</a>(dctx, ptr) ((<a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a>)(PetscDeviceDeallocate_Private((dctx), (ptr)) || ((ptr) = <a href="../manualpages/Sys/PETSC_NULLPTR.html">PETSC_NULLPTR</a>, <a href="../manualpages/Sys/PetscErrorCode.html">PETSC_SUCCESS</a>)))</font></strong>
<a name="line262">262: </a><font color="#B22222">/*MC</font>
<a name="line263">263: </a><font color="#B22222"> <a href="../manualpages/Device/PetscDeviceArrayCopy.html">PetscDeviceArrayCopy</a> - Copy memory in a device-aware manner</font>
<a name="line265">265: </a><font color="#B22222"> Synopsis:</font>
<a name="line266">266: </a>#include <A href="../include/petscdevice.h.html"><petscdevice.h></A>
<a name="line267">267: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceArrayCopy.html">PetscDeviceArrayCopy</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a> dctx, void *dest, const void *src, size_t n)</font>
<a name="line269">269: </a><font color="#B22222"> Not Collective, Asynchronous, Auto-dependency aware</font>
<a name="line271">271: </a><font color="#B22222"> Input Parameters:</font>
<a name="line272">272: </a><font color="#B22222">+ dctx - The `<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>` used to copy the memory</font>
<a name="line273">273: </a><font color="#B22222">. dest - The pointer to copy to</font>
<a name="line274">274: </a><font color="#B22222">. src - The pointer to copy from</font>
<a name="line275">275: </a><font color="#B22222">- n - The amount (in elements) to copy</font>
<a name="line277">277: </a><font color="#B22222"> Notes:</font>
<a name="line278">278: </a><font color="#B22222"> Both `dest` and `src` must have been allocated using `<a href="../manualpages/Device/PetscDeviceMalloc.html">PetscDeviceMalloc</a>()` or</font>
<a name="line279">279: </a><font color="#B22222"> `<a href="../manualpages/Device/PetscDeviceCalloc.html">PetscDeviceCalloc</a>()`.</font>
<a name="line281">281: </a><font color="#B22222"> This uses the `sizeof()` of the `src` memory type requested to determine the total memory to</font>
<a name="line282">282: </a><font color="#B22222"> be copied, therefore you should not multiply the number of elements by the `sizeof()` the</font>
<a name="line283">283: </a><font color="#B22222"> type\:</font>
<a name="line285">285: </a><font color="#B22222">.vb</font>
<a name="line286">286: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscInt.html">PetscInt</a> *to,*from;</font>
<a name="line288">288: </a><font color="#B22222"> // correct</font>
<a name="line289">289: </a><font color="#B22222"> <a href="../manualpages/Device/PetscDeviceArrayCopy.html">PetscDeviceArrayCopy</a>(dctx,to,from,n);</font>
<a name="line291">291: </a><font color="#B22222"> // incorrect</font>
<a name="line292">292: </a><font color="#B22222"> <a href="../manualpages/Device/PetscDeviceArrayCopy.html">PetscDeviceArrayCopy</a>(dctx,to,from,n*sizeof(*from));</font>
<a name="line293">293: </a><font color="#B22222">.ve</font>
<a name="line295">295: </a><font color="#B22222"> See `<a href="../manualpages/Device/PetscDeviceMemcpy.html">PetscDeviceMemcpy</a>()` for further discussion.</font>
<a name="line297">297: </a><font color="#B22222"> Level: beginner</font>
<a name="line299">299: </a><font color="#B22222">.N ASYNC_API</font>
<a name="line301">301: </a><font color="#B22222">.seealso: `<a href="../manualpages/Device/PetscDeviceMalloc.html">PetscDeviceMalloc</a>()`, `<a href="../manualpages/Device/PetscDeviceCalloc.html">PetscDeviceCalloc</a>()`, `<a href="../manualpages/Device/PetscDeviceFree.html">PetscDeviceFree</a>()`,</font>
<a name="line302">302: </a><font color="#B22222">`<a href="../manualpages/Device/PetscDeviceArrayZero.html">PetscDeviceArrayZero</a>()`, `<a href="../manualpages/Device/PetscDeviceMemcpy.html">PetscDeviceMemcpy</a>()`</font>
<a name="line303">303: </a><font color="#B22222">M*/</font>
<a name="line304">304: </a><strong><font color="#228B22">#define <a href="../manualpages/Device/PetscDeviceArrayCopy.html">PetscDeviceArrayCopy</a>(dctx, dest, src, n) <a href="../manualpages/Device/PetscDeviceMemcpy.html">PetscDeviceMemcpy</a>((dctx), (dest), (src), (size_t)(n) * sizeof(*(src)))</font></strong>
<a name="line306">306: </a><font color="#B22222">/*MC</font>
<a name="line307">307: </a><font color="#B22222"> <a href="../manualpages/Device/PetscDeviceArrayZero.html">PetscDeviceArrayZero</a> - Zero memory in a device-aware manner</font>
<a name="line309">309: </a><font color="#B22222"> Synopsis:</font>
<a name="line310">310: </a>#include <A href="../include/petscdevice.h.html"><petscdevice.h></A>
<a name="line311">311: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscErrorCode.html">PetscErrorCode</a> <a href="../manualpages/Device/PetscDeviceArrayZero.html">PetscDeviceArrayZero</a>(<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a> dctx, void *ptr, size_t n)</font>
<a name="line313">313: </a><font color="#B22222"> Not Collective, Asynchronous, Auto-dependency aware</font>
<a name="line315">315: </a><font color="#B22222"> Input Parameters:</font>
<a name="line316">316: </a><font color="#B22222">+ dctx - The `<a href="../manualpages/Sys/PetscDeviceContext.html">PetscDeviceContext</a>` used to zero the memory</font>
<a name="line317">317: </a><font color="#B22222">. ptr - The pointer to the memory</font>
<a name="line318">318: </a><font color="#B22222">- n - The amount (in elements) to zero</font>
<a name="line320">320: </a><font color="#B22222"> Level: beginner</font>
<a name="line322">322: </a><font color="#B22222"> Notes:</font>
<a name="line323">323: </a><font color="#B22222"> `ptr` must have been allocated using `<a href="../manualpages/Device/PetscDeviceMalloc.html">PetscDeviceMalloc</a>()` or `<a href="../manualpages/Device/PetscDeviceCalloc.html">PetscDeviceCalloc</a>()`.</font>
<a name="line325">325: </a><font color="#B22222"> This uses the `sizeof()` of the memory type requested to determine the total memory to be</font>
<a name="line326">326: </a><font color="#B22222"> zeroed, therefore you should not multiply the number of elements by the `sizeof()` the type\:</font>
<a name="line328">328: </a><font color="#B22222">.vb</font>
<a name="line329">329: </a><font color="#B22222"> <a href="../manualpages/Sys/PetscInt.html">PetscInt</a> *ptr;</font>
<a name="line331">331: </a><font color="#B22222"> // correct</font>
<a name="line332">332: </a><font color="#B22222"> <a href="../manualpages/Device/PetscDeviceArrayZero.html">PetscDeviceArrayZero</a>(dctx,ptr,n);</font>
<a name="line334">334: </a><font color="#B22222"> // incorrect</font>
<a name="line335">335: </a><font color="#B22222"> <a href="../manualpages/Device/PetscDeviceArrayZero.html">PetscDeviceArrayZero</a>(dctx,ptr,n*sizeof(*ptr));</font>
<a name="line336">336: </a><font color="#B22222">.ve</font>
<a name="line338">338: </a><font color="#B22222"> See `<a href="../manualpages/Device/PetscDeviceMemset.html">PetscDeviceMemset</a>()` for further discussion.</font>
<a name="line340">340: </a><font color="#B22222">.N ASYNC_API</font>
<a name="line342">342: </a><font color="#B22222">.seealso: `<a href="../manualpages/Device/PetscDeviceMalloc.html">PetscDeviceMalloc</a>()`, `<a href="../manualpages/Device/PetscDeviceCalloc.html">PetscDeviceCalloc</a>()`, `<a href="../manualpages/Device/PetscDeviceFree.html">PetscDeviceFree</a>()`,</font>
<a name="line343">343: </a><font color="#B22222">`<a href="../manualpages/Device/PetscDeviceArrayCopy.html">PetscDeviceArrayCopy</a>()`, `<a href="../manualpages/Device/PetscDeviceMemset.html">PetscDeviceMemset</a>()`</font>
<a name="line344">344: </a><font color="#B22222">M*/</font>
<a name="line345">345: </a><strong><font color="#228B22">#define <a href="../manualpages/Device/PetscDeviceArrayZero.html">PetscDeviceArrayZero</a>(dctx, ptr, n) <a href="../manualpages/Device/PetscDeviceMemset.html">PetscDeviceMemset</a>((dctx), (ptr), 0, (size_t)(n) * sizeof(*(ptr)))</font></strong>
</pre>
</body>
</html>
|