xref: /libCEED/rust/libceed-sys/c-src/backends/blocked/ceed-blocked.c (revision 472941f0c10177d86dfda5d1965729671a5c15be)
13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
34a2e7687Sjeremylt //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
54a2e7687Sjeremylt //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
74a2e7687Sjeremylt 
82b730f8bSJeremy L Thompson #include "ceed-blocked.h"
92b730f8bSJeremy L Thompson 
1049aac155SJeremy L Thompson #include <ceed.h>
11ec3da8bcSJed Brown #include <ceed/backend.h>
123d576824SJeremy L Thompson #include <stdbool.h>
133d576824SJeremy L Thompson #include <string.h>
144a2e7687Sjeremylt 
15f10650afSjeremylt //------------------------------------------------------------------------------
16f10650afSjeremylt // Backend Init
17f10650afSjeremylt //------------------------------------------------------------------------------
18*472941f0SJeremy L Thompson static int CeedInit_Blocked(const char *resource, Ceed ceed) {
196574a04fSJeremy L Thompson   CeedCheck(!strcmp(resource, "/cpu/self") || !strcmp(resource, "/cpu/self/ref/blocked"), ceed, CEED_ERROR_BACKEND,
206574a04fSJeremy L Thompson             "Blocked backend cannot use resource: %s", resource);
212b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetDeterministic(ceed, true));
224a2e7687Sjeremylt 
23ea61e9acSJeremy L Thompson   // Create reference Ceed that implementation will be dispatched through unless overridden
24d1d35e2fSjeremylt   Ceed ceed_ref;
252b730f8bSJeremy L Thompson   CeedCallBackend(CeedInit("/cpu/self/ref/serial", &ceed_ref));
262b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetDelegate(ceed, ceed_ref));
274a2e7687Sjeremylt 
28ea61e9acSJeremy L Thompson   // Set fallback Ceed resource for advanced operator functionality
29e2f04181SAndrew T. Barker   const char fallbackresource[] = "/cpu/self/ref/serial";
302b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetOperatorFallbackResource(ceed, fallbackresource));
31e2f04181SAndrew T. Barker 
322b730f8bSJeremy L Thompson   CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "OperatorCreate", CeedOperatorCreate_Blocked));
334a2e7687Sjeremylt 
34e15f9bd0SJeremy L Thompson   return CEED_ERROR_SUCCESS;
354a2e7687Sjeremylt }
364a2e7687Sjeremylt 
37f10650afSjeremylt //------------------------------------------------------------------------------
38f10650afSjeremylt // Backend Register
39f10650afSjeremylt //------------------------------------------------------------------------------
402b730f8bSJeremy L Thompson CEED_INTERN int CeedRegister_Ref_Blocked(void) { return CeedRegister("/cpu/self/ref/blocked", CeedInit_Blocked, 55); }
412a86cc9dSSebastian Grimberg 
42f10650afSjeremylt //------------------------------------------------------------------------------
43