xref: /libCEED/rust/libceed-sys/c-src/backends/opt/ceed-opt-serial.c (revision f10650af6497af6d0949b45f2eee824400fc9b71)
189c6efa4Sjeremylt // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
289c6efa4Sjeremylt // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
389c6efa4Sjeremylt // All Rights reserved. See files LICENSE and NOTICE for details.
489c6efa4Sjeremylt //
589c6efa4Sjeremylt // This file is part of CEED, a collection of benchmarks, miniapps, software
689c6efa4Sjeremylt // libraries and APIs for efficient high-order finite element and spectral
789c6efa4Sjeremylt // element discretizations for exascale applications. For more information and
889c6efa4Sjeremylt // source code availability see http://github.com/ceed.
989c6efa4Sjeremylt //
1089c6efa4Sjeremylt // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
1189c6efa4Sjeremylt // a collaborative effort of two U.S. Department of Energy organizations (Office
1289c6efa4Sjeremylt // of Science and the National Nuclear Security Administration) responsible for
1389c6efa4Sjeremylt // the planning and preparation of a capable exascale ecosystem, including
1489c6efa4Sjeremylt // software, applications, hardware, advanced system engineering and early
1589c6efa4Sjeremylt // testbed platforms, in support of the nation's exascale computing imperative.
1689c6efa4Sjeremylt 
1789c6efa4Sjeremylt #include <string.h>
1889c6efa4Sjeremylt #include "ceed-opt.h"
1989c6efa4Sjeremylt 
20*f10650afSjeremylt //------------------------------------------------------------------------------
21*f10650afSjeremylt // Backend Destroy
22*f10650afSjeremylt //------------------------------------------------------------------------------
2389c6efa4Sjeremylt static int CeedDestroy_Opt(Ceed ceed) {
2489c6efa4Sjeremylt   int ierr;
2589c6efa4Sjeremylt   Ceed_Opt *data;
2689c6efa4Sjeremylt   ierr = CeedGetData(ceed, (void *)&data); CeedChk(ierr);
2789c6efa4Sjeremylt   ierr = CeedFree(&data); CeedChk(ierr);
2889c6efa4Sjeremylt 
2989c6efa4Sjeremylt   return 0;
3089c6efa4Sjeremylt }
3189c6efa4Sjeremylt 
32*f10650afSjeremylt //------------------------------------------------------------------------------
33*f10650afSjeremylt // Backend Init
34*f10650afSjeremylt //------------------------------------------------------------------------------
3589c6efa4Sjeremylt static int CeedInit_Opt_Serial(const char *resource, Ceed ceed) {
3689c6efa4Sjeremylt   int ierr;
3789c6efa4Sjeremylt   if (strcmp(resource, "/cpu/self")
3889c6efa4Sjeremylt       && strcmp(resource, "/cpu/self/opt/serial"))
39c042f62fSJeremy L Thompson     // LCOV_EXCL_START
4089c6efa4Sjeremylt     return CeedError(ceed, 1, "Opt backend cannot use resource: %s", resource);
41c042f62fSJeremy L Thompson   // LCOV_EXCL_STOP
4289c6efa4Sjeremylt 
4389c6efa4Sjeremylt   // Create refrence CEED that implementation will be dispatched
4489c6efa4Sjeremylt   //   through unless overridden
456f7d248dSjeremylt   Ceed ceedref;
4689c6efa4Sjeremylt   CeedInit("/cpu/self/ref/serial", &ceedref);
47a4999eddSjeremylt   ierr = CeedSetDelegate(ceed, ceedref); CeedChk(ierr);
4889c6efa4Sjeremylt 
4989c6efa4Sjeremylt   ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy",
5089c6efa4Sjeremylt                                 CeedDestroy_Opt); CeedChk(ierr);
5189c6efa4Sjeremylt   ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "OperatorCreate",
5289c6efa4Sjeremylt                                 CeedOperatorCreate_Opt); CeedChk(ierr);
5389c6efa4Sjeremylt 
5489c6efa4Sjeremylt   // Set blocksize
5589c6efa4Sjeremylt   Ceed_Opt *data;
5689c6efa4Sjeremylt   ierr = CeedCalloc(1, &data); CeedChk(ierr);
5789c6efa4Sjeremylt   data->blksize = 1;
5889c6efa4Sjeremylt   ierr = CeedSetData(ceed, (void *)&data); CeedChk(ierr);
5989c6efa4Sjeremylt 
6089c6efa4Sjeremylt   return 0;
6189c6efa4Sjeremylt }
6289c6efa4Sjeremylt 
63*f10650afSjeremylt //------------------------------------------------------------------------------
64*f10650afSjeremylt // Backend Register
65*f10650afSjeremylt //------------------------------------------------------------------------------
6689c6efa4Sjeremylt __attribute__((constructor))
6789c6efa4Sjeremylt static void Register(void) {
6889c6efa4Sjeremylt   CeedRegister("/cpu/self/opt/serial", CeedInit_Opt_Serial, 45);
6989c6efa4Sjeremylt }
70*f10650afSjeremylt //------------------------------------------------------------------------------
71