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 17ec3da8bcSJed Brown #include <ceed/ceed.h> 18ec3da8bcSJed Brown #include <ceed/backend.h> 193d576824SJeremy L Thompson #include <stdbool.h> 2089c6efa4Sjeremylt #include <string.h> 2189c6efa4Sjeremylt #include "ceed-opt.h" 2289c6efa4Sjeremylt 23f10650afSjeremylt //------------------------------------------------------------------------------ 24f10650afSjeremylt // Backend Destroy 25f10650afSjeremylt //------------------------------------------------------------------------------ 2689c6efa4Sjeremylt static int CeedDestroy_Opt(Ceed ceed) { 2789c6efa4Sjeremylt int ierr; 2889c6efa4Sjeremylt Ceed_Opt *data; 29e15f9bd0SJeremy L Thompson ierr = CeedGetData(ceed, &data); CeedChkBackend(ierr); 30e15f9bd0SJeremy L Thompson ierr = CeedFree(&data); CeedChkBackend(ierr); 3189c6efa4Sjeremylt 32e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 3389c6efa4Sjeremylt } 3489c6efa4Sjeremylt 35f10650afSjeremylt //------------------------------------------------------------------------------ 36f10650afSjeremylt // Backend Init 37f10650afSjeremylt //------------------------------------------------------------------------------ 3889c6efa4Sjeremylt static int CeedInit_Opt_Serial(const char *resource, Ceed ceed) { 3989c6efa4Sjeremylt int ierr; 4089c6efa4Sjeremylt if (strcmp(resource, "/cpu/self") 4189c6efa4Sjeremylt && strcmp(resource, "/cpu/self/opt/serial")) 42c042f62fSJeremy L Thompson // LCOV_EXCL_START 43e15f9bd0SJeremy L Thompson return CeedError(ceed, CEED_ERROR_BACKEND, 44e15f9bd0SJeremy L Thompson "Opt backend cannot use resource: %s", resource); 45c042f62fSJeremy L Thompson // LCOV_EXCL_STOP 46e15f9bd0SJeremy L Thompson ierr = CeedSetDeterministic(ceed, true); CeedChkBackend(ierr); 4789c6efa4Sjeremylt 485f67fadeSJeremy L Thompson // Create reference CEED that implementation will be dispatched 4989c6efa4Sjeremylt // through unless overridden 50*d1d35e2fSjeremylt Ceed ceed_ref; 51*d1d35e2fSjeremylt CeedInit("/cpu/self/ref/serial", &ceed_ref); 52*d1d35e2fSjeremylt ierr = CeedSetDelegate(ceed, ceed_ref); CeedChkBackend(ierr); 5389c6efa4Sjeremylt 54e2f04181SAndrew T. Barker // Set fallback CEED resource for advanced operator functionality 55e2f04181SAndrew T. Barker const char fallbackresource[] = "/cpu/self/ref/serial"; 56e2f04181SAndrew T. Barker ierr = CeedSetOperatorFallbackResource(ceed, fallbackresource); 57e2f04181SAndrew T. Barker CeedChkBackend(ierr); 58e2f04181SAndrew T. Barker 5989c6efa4Sjeremylt ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy", 60e15f9bd0SJeremy L Thompson CeedDestroy_Opt); CeedChkBackend(ierr); 6189c6efa4Sjeremylt ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "OperatorCreate", 62e15f9bd0SJeremy L Thompson CeedOperatorCreate_Opt); CeedChkBackend(ierr); 6389c6efa4Sjeremylt 6489c6efa4Sjeremylt // Set blocksize 6589c6efa4Sjeremylt Ceed_Opt *data; 66e15f9bd0SJeremy L Thompson ierr = CeedCalloc(1, &data); CeedChkBackend(ierr); 67*d1d35e2fSjeremylt data->blk_size = 1; 68e15f9bd0SJeremy L Thompson ierr = CeedSetData(ceed, data); CeedChkBackend(ierr); 6989c6efa4Sjeremylt 70e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 7189c6efa4Sjeremylt } 7289c6efa4Sjeremylt 73f10650afSjeremylt //------------------------------------------------------------------------------ 74f10650afSjeremylt // Backend Register 75f10650afSjeremylt //------------------------------------------------------------------------------ 761d013790SJed Brown CEED_INTERN int CeedRegister_Opt_Serial(void) { 771d013790SJed Brown return CeedRegister("/cpu/self/opt/serial", CeedInit_Opt_Serial, 45); 7889c6efa4Sjeremylt } 791d013790SJed Brown 80f10650afSjeremylt //------------------------------------------------------------------------------ 81