xref: /libCEED/backends/memcheck/ceed-memcheck-vector.c (revision 9937a20e594bfb4e867db08aa6f5f4a7e0ba1b8e)
15aed82e4SJeremy L Thompson // Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors.
29798701eSJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
39798701eSJeremy L Thompson //
49798701eSJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
59798701eSJeremy L Thompson //
69798701eSJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
79798701eSJeremy L Thompson 
849aac155SJeremy L Thompson #include <ceed.h>
99798701eSJeremy L Thompson #include <ceed/backend.h>
109798701eSJeremy L Thompson #include <math.h>
1149aac155SJeremy L Thompson #include <stdbool.h>
129798701eSJeremy L Thompson #include <string.h>
139798701eSJeremy L Thompson #include <valgrind/memcheck.h>
149798701eSJeremy L Thompson 
159798701eSJeremy L Thompson #include "ceed-memcheck.h"
169798701eSJeremy L Thompson 
179798701eSJeremy L Thompson //------------------------------------------------------------------------------
189798701eSJeremy L Thompson // Has Valid Array
199798701eSJeremy L Thompson //------------------------------------------------------------------------------
209798701eSJeremy L Thompson static int CeedVectorHasValidArray_Memcheck(CeedVector vec, bool *has_valid_array) {
219798701eSJeremy L Thompson   CeedVector_Memcheck *impl;
22ad70ee2cSJeremy L Thompson 
239798701eSJeremy L Thompson   CeedCallBackend(CeedVectorGetData(vec, &impl));
24*9937a20eSJeremy L Thompson   *has_valid_array = !!impl->array_allocated;
259798701eSJeremy L Thompson   return CEED_ERROR_SUCCESS;
269798701eSJeremy L Thompson }
279798701eSJeremy L Thompson 
289798701eSJeremy L Thompson //------------------------------------------------------------------------------
299798701eSJeremy L Thompson // Check if has borrowed array of given type
309798701eSJeremy L Thompson //------------------------------------------------------------------------------
319798701eSJeremy L Thompson static inline int CeedVectorHasBorrowedArrayOfType_Memcheck(const CeedVector vec, CeedMemType mem_type, bool *has_borrowed_array_of_type) {
32ad70ee2cSJeremy L Thompson   CeedVector_Memcheck *impl;
33ad70ee2cSJeremy L Thompson 
346e536b99SJeremy L Thompson   CeedCheck(mem_type == CEED_MEM_HOST, CeedVectorReturnCeed(vec), CEED_ERROR_BACKEND, "Can only set HOST memory for this backend");
35*9937a20eSJeremy L Thompson 
36*9937a20eSJeremy L Thompson   CeedCallBackend(CeedVectorGetData(vec, &impl));
37*9937a20eSJeremy L Thompson   *has_borrowed_array_of_type = !!impl->array_borrowed;
389798701eSJeremy L Thompson   return CEED_ERROR_SUCCESS;
399798701eSJeremy L Thompson }
409798701eSJeremy L Thompson 
419798701eSJeremy L Thompson //------------------------------------------------------------------------------
429798701eSJeremy L Thompson // Vector Set Array
439798701eSJeremy L Thompson //------------------------------------------------------------------------------
449798701eSJeremy L Thompson static int CeedVectorSetArray_Memcheck(CeedVector vec, CeedMemType mem_type, CeedCopyMode copy_mode, CeedScalar *array) {
45ad70ee2cSJeremy L Thompson   CeedSize             length;
46ad70ee2cSJeremy L Thompson   CeedVector_Memcheck *impl;
47ad70ee2cSJeremy L Thompson 
48*9937a20eSJeremy L Thompson   CeedCheck(mem_type == CEED_MEM_HOST, CeedVectorReturnCeed(vec), CEED_ERROR_BACKEND, "Can only set HOST memory for this backend");
49*9937a20eSJeremy L Thompson 
50ad70ee2cSJeremy L Thompson   CeedCallBackend(CeedVectorGetData(vec, &impl));
51ad70ee2cSJeremy L Thompson   CeedCallBackend(CeedVectorGetLength(vec, &length));
529798701eSJeremy L Thompson 
53*9937a20eSJeremy L Thompson   // Clear previous owned arrays
54d1931fc8SJeremy L Thompson   if (impl->array_allocated) {
55d1931fc8SJeremy L Thompson     for (CeedSize i = 0; i < length; i++) impl->array_allocated[i] = NAN;
56d1931fc8SJeremy L Thompson   }
579798701eSJeremy L Thompson   CeedCallBackend(CeedFree(&impl->array_allocated));
58*9937a20eSJeremy L Thompson   VALGRIND_DISCARD(impl->allocated_block_id);
59d1931fc8SJeremy L Thompson   if (impl->array_owned) {
60d1931fc8SJeremy L Thompson     for (CeedSize i = 0; i < length; i++) impl->array_owned[i] = NAN;
61d1931fc8SJeremy L Thompson   }
62*9937a20eSJeremy L Thompson   VALGRIND_DISCARD(impl->owned_block_id);
639798701eSJeremy L Thompson   CeedCallBackend(CeedFree(&impl->array_owned));
64*9937a20eSJeremy L Thompson 
65*9937a20eSJeremy L Thompson   // Clear borrowed block id, if present
66*9937a20eSJeremy L Thompson   if (impl->array_borrowed) VALGRIND_DISCARD(impl->borrowed_block_id);
67*9937a20eSJeremy L Thompson 
68*9937a20eSJeremy L Thompson   // Set internal pointers to external arrays
699798701eSJeremy L Thompson   switch (copy_mode) {
709798701eSJeremy L Thompson     case CEED_COPY_VALUES:
71*9937a20eSJeremy L Thompson       impl->array_owned    = NULL;
729798701eSJeremy L Thompson       impl->array_borrowed = NULL;
739798701eSJeremy L Thompson       break;
749798701eSJeremy L Thompson     case CEED_OWN_POINTER:
759798701eSJeremy L Thompson       impl->array_owned    = array;
769798701eSJeremy L Thompson       impl->array_borrowed = NULL;
77*9937a20eSJeremy L Thompson       impl->owned_block_id = VALGRIND_CREATE_BLOCK(impl->array_owned, length * sizeof(CeedScalar), "Owned external array buffer");
789798701eSJeremy L Thompson       break;
799798701eSJeremy L Thompson     case CEED_USE_POINTER:
80*9937a20eSJeremy L Thompson       impl->array_owned       = NULL;
819798701eSJeremy L Thompson       impl->array_borrowed    = array;
82*9937a20eSJeremy L Thompson       impl->borrowed_block_id = VALGRIND_CREATE_BLOCK(impl->array_borrowed, length * sizeof(CeedScalar), "Borrowed external array buffer");
83*9937a20eSJeremy L Thompson       break;
849798701eSJeremy L Thompson   }
85*9937a20eSJeremy L Thompson 
86*9937a20eSJeremy L Thompson   // Create internal array data buffer
879798701eSJeremy L Thompson   CeedCallBackend(CeedCalloc(length, &impl->array_allocated));
88*9937a20eSJeremy L Thompson   impl->allocated_block_id = VALGRIND_CREATE_BLOCK(impl->array_allocated, length * sizeof(CeedScalar), "Allocated internal array buffer");
89*9937a20eSJeremy L Thompson   if (array) {
90*9937a20eSJeremy L Thompson     memcpy(impl->array_allocated, array, length * sizeof(CeedScalar));
91*9937a20eSJeremy L Thompson   } else {
92*9937a20eSJeremy L Thompson     for (CeedInt i = 0; i < length; i++) impl->array_allocated[i] = NAN;
93*9937a20eSJeremy L Thompson   }
94*9937a20eSJeremy L Thompson   return CEED_ERROR_SUCCESS;
95*9937a20eSJeremy L Thompson }
96*9937a20eSJeremy L Thompson 
97*9937a20eSJeremy L Thompson //------------------------------------------------------------------------------
98*9937a20eSJeremy L Thompson // Sync arrays
99*9937a20eSJeremy L Thompson //------------------------------------------------------------------------------
100*9937a20eSJeremy L Thompson static int CeedVectorSyncArray_Memcheck(const CeedVector vec, CeedMemType mem_type) {
101*9937a20eSJeremy L Thompson   CeedSize             length;
102*9937a20eSJeremy L Thompson   CeedVector_Memcheck *impl;
103*9937a20eSJeremy L Thompson 
104*9937a20eSJeremy L Thompson   CeedCheck(mem_type == CEED_MEM_HOST, CeedVectorReturnCeed(vec), CEED_ERROR_BACKEND, "Can only provide HOST memory for this backend");
105*9937a20eSJeremy L Thompson 
106*9937a20eSJeremy L Thompson   CeedCallBackend(CeedVectorGetData(vec, &impl));
107*9937a20eSJeremy L Thompson   CeedCallBackend(CeedVectorGetLength(vec, &length));
108*9937a20eSJeremy L Thompson 
109*9937a20eSJeremy L Thompson   // Copy internal buffer back to owned or borrowed array
110*9937a20eSJeremy L Thompson   if (impl->array_owned) {
111*9937a20eSJeremy L Thompson     memcpy(impl->array_owned, impl->array_allocated, length * sizeof(CeedScalar));
112*9937a20eSJeremy L Thompson   }
113*9937a20eSJeremy L Thompson   if (impl->array_borrowed) {
114*9937a20eSJeremy L Thompson     memcpy(impl->array_borrowed, impl->array_allocated, length * sizeof(CeedScalar));
115*9937a20eSJeremy L Thompson   }
1169798701eSJeremy L Thompson   return CEED_ERROR_SUCCESS;
1179798701eSJeremy L Thompson }
1189798701eSJeremy L Thompson 
1199798701eSJeremy L Thompson //------------------------------------------------------------------------------
1209798701eSJeremy L Thompson // Vector Take Array
1219798701eSJeremy L Thompson //------------------------------------------------------------------------------
1229798701eSJeremy L Thompson static int CeedVectorTakeArray_Memcheck(CeedVector vec, CeedMemType mem_type, CeedScalar **array) {
123d1931fc8SJeremy L Thompson   CeedSize             length;
124ad70ee2cSJeremy L Thompson   CeedVector_Memcheck *impl;
125ad70ee2cSJeremy L Thompson 
126*9937a20eSJeremy L Thompson   CeedCheck(mem_type == CEED_MEM_HOST, CeedVectorReturnCeed(vec), CEED_ERROR_BACKEND, "Can only provide HOST memory for this backend");
127*9937a20eSJeremy L Thompson 
128ad70ee2cSJeremy L Thompson   CeedCallBackend(CeedVectorGetData(vec, &impl));
129d1931fc8SJeremy L Thompson   CeedCallBackend(CeedVectorGetLength(vec, &length));
1309798701eSJeremy L Thompson 
131*9937a20eSJeremy L Thompson   // Synchronize memory
132*9937a20eSJeremy L Thompson   CeedCallBackend(CeedVectorSyncArray_Memcheck(vec, CEED_MEM_HOST));
1339798701eSJeremy L Thompson 
134*9937a20eSJeremy L Thompson   // Return borrowed array
1359798701eSJeremy L Thompson   (*array)             = impl->array_borrowed;
1369798701eSJeremy L Thompson   impl->array_borrowed = NULL;
137*9937a20eSJeremy L Thompson   VALGRIND_DISCARD(impl->borrowed_block_id);
138*9937a20eSJeremy L Thompson 
139*9937a20eSJeremy L Thompson   // De-allocate internal memory
140d1931fc8SJeremy L Thompson   if (impl->array_allocated) {
141d1931fc8SJeremy L Thompson     for (CeedSize i = 0; i < length; i++) impl->array_allocated[i] = NAN;
142d1931fc8SJeremy L Thompson   }
1439798701eSJeremy L Thompson   CeedCallBackend(CeedFree(&impl->array_allocated));
144*9937a20eSJeremy L Thompson   VALGRIND_DISCARD(impl->allocated_block_id);
1459798701eSJeremy L Thompson   return CEED_ERROR_SUCCESS;
1469798701eSJeremy L Thompson }
1479798701eSJeremy L Thompson 
1489798701eSJeremy L Thompson //------------------------------------------------------------------------------
1499798701eSJeremy L Thompson // Vector Get Array
1509798701eSJeremy L Thompson //------------------------------------------------------------------------------
1519798701eSJeremy L Thompson static int CeedVectorGetArray_Memcheck(CeedVector vec, CeedMemType mem_type, CeedScalar **array) {
1521a3e18b3SJeremy L Thompson   CeedSize             length;
153ad70ee2cSJeremy L Thompson   CeedVector_Memcheck *impl;
154ad70ee2cSJeremy L Thompson 
155*9937a20eSJeremy L Thompson   CeedCheck(mem_type == CEED_MEM_HOST, CeedVectorReturnCeed(vec), CEED_ERROR_BACKEND, "Can only provide HOST memory for this backend");
156*9937a20eSJeremy L Thompson 
157ad70ee2cSJeremy L Thompson   CeedCallBackend(CeedVectorGetData(vec, &impl));
1581a3e18b3SJeremy L Thompson   CeedCallBackend(CeedVectorGetLength(vec, &length));
1599798701eSJeremy L Thompson 
160*9937a20eSJeremy L Thompson   // Create and return writable buffer
1611a3e18b3SJeremy L Thompson   CeedCallBackend(CeedCalloc(length, &impl->array_writable_copy));
162*9937a20eSJeremy L Thompson   impl->writable_block_id = VALGRIND_CREATE_BLOCK(impl->array_writable_copy, length * sizeof(CeedScalar), "Allocated writeable array buffer copy");
163*9937a20eSJeremy L Thompson   memcpy(impl->array_writable_copy, impl->array_allocated, length * sizeof(CeedScalar));
1641a3e18b3SJeremy L Thompson   *array = impl->array_writable_copy;
1659798701eSJeremy L Thompson   return CEED_ERROR_SUCCESS;
1669798701eSJeremy L Thompson }
1679798701eSJeremy L Thompson 
1689798701eSJeremy L Thompson //------------------------------------------------------------------------------
1699798701eSJeremy L Thompson // Vector Get Array Read
1709798701eSJeremy L Thompson //------------------------------------------------------------------------------
1719798701eSJeremy L Thompson static int CeedVectorGetArrayRead_Memcheck(CeedVector vec, CeedMemType mem_type, const CeedScalar **array) {
172ad70ee2cSJeremy L Thompson   CeedSize             length;
173ad70ee2cSJeremy L Thompson   CeedVector_Memcheck *impl;
174ad70ee2cSJeremy L Thompson 
175*9937a20eSJeremy L Thompson   CeedCheck(mem_type == CEED_MEM_HOST, CeedVectorReturnCeed(vec), CEED_ERROR_BACKEND, "Can only provide HOST memory for this backend");
176*9937a20eSJeremy L Thompson 
177ad70ee2cSJeremy L Thompson   CeedCallBackend(CeedVectorGetData(vec, &impl));
178ad70ee2cSJeremy L Thompson   CeedCallBackend(CeedVectorGetLength(vec, &length));
1799798701eSJeremy L Thompson 
180*9937a20eSJeremy L Thompson   // Create and return read-only buffer
1815b5dc0c8SJeremy L Thompson   if (!impl->array_read_only_copy) {
1829798701eSJeremy L Thompson     CeedCallBackend(CeedCalloc(length, &impl->array_read_only_copy));
183*9937a20eSJeremy L Thompson     impl->writable_block_id = VALGRIND_CREATE_BLOCK(impl->array_read_only_copy, length * sizeof(CeedScalar), "Allocated read-only array buffer copy");
184*9937a20eSJeremy L Thompson     memcpy(impl->array_read_only_copy, impl->array_allocated, length * sizeof(CeedScalar));
1855b5dc0c8SJeremy L Thompson   }
186d1931fc8SJeremy L Thompson   *array = impl->array_read_only_copy;
1879798701eSJeremy L Thompson   return CEED_ERROR_SUCCESS;
1889798701eSJeremy L Thompson }
1899798701eSJeremy L Thompson 
1909798701eSJeremy L Thompson //------------------------------------------------------------------------------
1919798701eSJeremy L Thompson // Vector Get Array Write
1929798701eSJeremy L Thompson //------------------------------------------------------------------------------
1939798701eSJeremy L Thompson static int CeedVectorGetArrayWrite_Memcheck(CeedVector vec, CeedMemType mem_type, CeedScalar **array) {
194ad70ee2cSJeremy L Thompson   CeedSize             length;
195ad70ee2cSJeremy L Thompson   CeedVector_Memcheck *impl;
196ad70ee2cSJeremy L Thompson 
197*9937a20eSJeremy L Thompson   CeedCheck(mem_type == CEED_MEM_HOST, CeedVectorReturnCeed(vec), CEED_ERROR_BACKEND, "Can only provide HOST memory for this backend");
198*9937a20eSJeremy L Thompson 
199ad70ee2cSJeremy L Thompson   CeedCallBackend(CeedVectorGetData(vec, &impl));
200ad70ee2cSJeremy L Thompson   CeedCallBackend(CeedVectorGetLength(vec, &length));
2019798701eSJeremy L Thompson 
202*9937a20eSJeremy L Thompson   // Allocate buffer if necessary
203*9937a20eSJeremy L Thompson   if (!impl->array_allocated) CeedCallBackend(CeedVectorSetArray_Memcheck(vec, mem_type, CEED_COPY_VALUES, NULL));
204*9937a20eSJeremy L Thompson 
205*9937a20eSJeremy L Thompson   // Get writable buffer
2069798701eSJeremy L Thompson   CeedCallBackend(CeedVectorGetArray_Memcheck(vec, mem_type, array));
207*9937a20eSJeremy L Thompson 
208*9937a20eSJeremy L Thompson   // Invalidate array data to prevent accidental reads
209dd39767dSJeremy L Thompson   for (CeedSize i = 0; i < length; i++) (*array)[i] = NAN;
210df852985SJeremy L Thompson   impl->is_write_only_access = true;
2119798701eSJeremy L Thompson   return CEED_ERROR_SUCCESS;
2129798701eSJeremy L Thompson }
2139798701eSJeremy L Thompson 
2149798701eSJeremy L Thompson //------------------------------------------------------------------------------
2159798701eSJeremy L Thompson // Vector Restore Array
2169798701eSJeremy L Thompson //------------------------------------------------------------------------------
2179798701eSJeremy L Thompson static int CeedVectorRestoreArray_Memcheck(CeedVector vec) {
2189798701eSJeremy L Thompson   Ceed                 ceed;
219ad70ee2cSJeremy L Thompson   CeedSize             length;
220ad70ee2cSJeremy L Thompson   CeedVector_Memcheck *impl;
221ad70ee2cSJeremy L Thompson 
222*9937a20eSJeremy L Thompson   CeedCallBackend(CeedVectorGetCeed(vec, &ceed));
223ad70ee2cSJeremy L Thompson   CeedCallBackend(CeedVectorGetData(vec, &impl));
224ad70ee2cSJeremy L Thompson   CeedCallBackend(CeedVectorGetLength(vec, &length));
2259798701eSJeremy L Thompson 
226*9937a20eSJeremy L Thompson   // Check for unset entries after write-only access
227df852985SJeremy L Thompson   if (impl->is_write_only_access) {
228dd39767dSJeremy L Thompson     for (CeedSize i = 0; i < length; i++) {
229*9937a20eSJeremy L Thompson       if (isnan(impl->array_writable_copy[i]))
230249f8407SJeremy L Thompson         CeedDebug256(ceed, CEED_DEBUG_COLOR_WARNING, "WARNING: Vec entry %" CeedSize_FMT " is NaN after restoring write-only access", i);
231df852985SJeremy L Thompson     }
232df852985SJeremy L Thompson     impl->is_write_only_access = false;
233df852985SJeremy L Thompson   }
234*9937a20eSJeremy L Thompson 
235*9937a20eSJeremy L Thompson   // Copy back to internal buffer and sync
236*9937a20eSJeremy L Thompson   memcpy(impl->array_allocated, impl->array_writable_copy, length * sizeof(CeedScalar));
237*9937a20eSJeremy L Thompson   CeedCallBackend(CeedVectorSyncArray_Memcheck(vec, CEED_MEM_HOST));
238*9937a20eSJeremy L Thompson 
239*9937a20eSJeremy L Thompson   // Invalidate writable buffer
240*9937a20eSJeremy L Thompson   for (CeedSize i = 0; i < length; i++) impl->array_writable_copy[i] = NAN;
241*9937a20eSJeremy L Thompson   CeedCallBackend(CeedFree(&impl->array_writable_copy));
242*9937a20eSJeremy L Thompson   VALGRIND_DISCARD(impl->writable_block_id);
2439798701eSJeremy L Thompson   return CEED_ERROR_SUCCESS;
2449798701eSJeremy L Thompson }
2459798701eSJeremy L Thompson 
2469798701eSJeremy L Thompson //------------------------------------------------------------------------------
2479798701eSJeremy L Thompson // Vector Restore Array Read-Only
2489798701eSJeremy L Thompson //------------------------------------------------------------------------------
2499798701eSJeremy L Thompson static int CeedVectorRestoreArrayRead_Memcheck(CeedVector vec) {
250*9937a20eSJeremy L Thompson   Ceed                 ceed;
251ad70ee2cSJeremy L Thompson   CeedSize             length;
252ad70ee2cSJeremy L Thompson   CeedVector_Memcheck *impl;
253ad70ee2cSJeremy L Thompson 
254*9937a20eSJeremy L Thompson   CeedCallBackend(CeedVectorGetCeed(vec, &ceed));
255ad70ee2cSJeremy L Thompson   CeedCallBackend(CeedVectorGetData(vec, &impl));
256ad70ee2cSJeremy L Thompson   CeedCallBackend(CeedVectorGetLength(vec, &length));
2579798701eSJeremy L Thompson 
258*9937a20eSJeremy L Thompson   // Verify no changes made during read-only access
259*9937a20eSJeremy L Thompson   bool is_changed = memcmp(impl->array_allocated, impl->array_read_only_copy, length * sizeof(CeedScalar));
2609798701eSJeremy L Thompson 
261*9937a20eSJeremy L Thompson   CeedCheck(!is_changed, ceed, CEED_ERROR_BACKEND, "Array data changed while accessed in read-only mode");
262*9937a20eSJeremy L Thompson 
263*9937a20eSJeremy L Thompson   // Invalidate read-only buffer
264d1931fc8SJeremy L Thompson   for (CeedSize i = 0; i < length; i++) impl->array_read_only_copy[i] = NAN;
2659798701eSJeremy L Thompson   CeedCallBackend(CeedFree(&impl->array_read_only_copy));
266*9937a20eSJeremy L Thompson   VALGRIND_DISCARD(impl->read_only_block_id);
2679798701eSJeremy L Thompson   return CEED_ERROR_SUCCESS;
2689798701eSJeremy L Thompson }
2699798701eSJeremy L Thompson 
2709798701eSJeremy L Thompson //------------------------------------------------------------------------------
2719798701eSJeremy L Thompson // Vector Destroy
2729798701eSJeremy L Thompson //------------------------------------------------------------------------------
2739798701eSJeremy L Thompson static int CeedVectorDestroy_Memcheck(CeedVector vec) {
2749798701eSJeremy L Thompson   CeedVector_Memcheck *impl;
2759798701eSJeremy L Thompson 
276*9937a20eSJeremy L Thompson   // Free allocations and discard block ids
277ad70ee2cSJeremy L Thompson   CeedCallBackend(CeedVectorGetData(vec, &impl));
278*9937a20eSJeremy L Thompson   if (impl->array_allocated) {
2799798701eSJeremy L Thompson     CeedCallBackend(CeedFree(&impl->array_allocated));
280*9937a20eSJeremy L Thompson     VALGRIND_DISCARD(impl->allocated_block_id);
281*9937a20eSJeremy L Thompson   }
282*9937a20eSJeremy L Thompson   if (impl->array_owned) {
2839798701eSJeremy L Thompson     CeedCallBackend(CeedFree(&impl->array_owned));
284*9937a20eSJeremy L Thompson     VALGRIND_DISCARD(impl->owned_block_id);
285*9937a20eSJeremy L Thompson   }
286*9937a20eSJeremy L Thompson   if (impl->array_borrowed) {
287*9937a20eSJeremy L Thompson     VALGRIND_DISCARD(impl->borrowed_block_id);
288*9937a20eSJeremy L Thompson   }
2899798701eSJeremy L Thompson   CeedCallBackend(CeedFree(&impl));
2909798701eSJeremy L Thompson   return CEED_ERROR_SUCCESS;
2919798701eSJeremy L Thompson }
2929798701eSJeremy L Thompson 
2939798701eSJeremy L Thompson //------------------------------------------------------------------------------
2949798701eSJeremy L Thompson // Vector Create
2959798701eSJeremy L Thompson //------------------------------------------------------------------------------
2969798701eSJeremy L Thompson int CeedVectorCreate_Memcheck(CeedSize n, CeedVector vec) {
2979798701eSJeremy L Thompson   Ceed                 ceed;
298ad70ee2cSJeremy L Thompson   CeedVector_Memcheck *impl;
2999798701eSJeremy L Thompson 
3009e82028bSJeremy L Thompson   CeedCallBackend(CeedCalloc(1, &impl));
3019e82028bSJeremy L Thompson   CeedCallBackend(CeedVectorSetData(vec, impl));
3029e82028bSJeremy L Thompson 
303ad70ee2cSJeremy L Thompson   CeedCallBackend(CeedVectorGetCeed(vec, &ceed));
3049798701eSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "HasValidArray", CeedVectorHasValidArray_Memcheck));
3059798701eSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "HasBorrowedArrayOfType", CeedVectorHasBorrowedArrayOfType_Memcheck));
3069798701eSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "SetArray", CeedVectorSetArray_Memcheck));
307*9937a20eSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "SyncArray", CeedVectorSyncArray_Memcheck));
3089798701eSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "TakeArray", CeedVectorTakeArray_Memcheck));
3099798701eSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "GetArray", CeedVectorGetArray_Memcheck));
3109798701eSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "GetArrayRead", CeedVectorGetArrayRead_Memcheck));
3119798701eSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "GetArrayWrite", CeedVectorGetArrayWrite_Memcheck));
3129798701eSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "RestoreArray", CeedVectorRestoreArray_Memcheck));
3139798701eSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "RestoreArrayRead", CeedVectorRestoreArrayRead_Memcheck));
3149798701eSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Vector", vec, "Destroy", CeedVectorDestroy_Memcheck));
3159798701eSJeremy L Thompson   return CEED_ERROR_SUCCESS;
3169798701eSJeremy L Thompson }
3172a86cc9dSSebastian Grimberg 
3189798701eSJeremy L Thompson //------------------------------------------------------------------------------
319