1 // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC. 2 // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707. 3 // All Rights reserved. See files LICENSE and NOTICE for details. 4 // 5 // This file is part of CEED, a collection of benchmarks, miniapps, software 6 // libraries and APIs for efficient high-order finite element and spectral 7 // element discretizations for exascale applications. For more information and 8 // source code availability see http://github.com/ceed. 9 // 10 // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 11 // a collaborative effort of two U.S. Department of Energy organizations (Office 12 // of Science and the National Nuclear Security Administration) responsible for 13 // the planning and preparation of a capable exascale ecosystem, including 14 // software, applications, hardware, advanced system engineering and early 15 // testbed platforms, in support of the nation's exascale computing imperative. 16 17 #include <ceed/ceed.h> 18 #include <ceed/backend.h> 19 #include <stdbool.h> 20 #include <string.h> 21 #include "ceed-opt.h" 22 23 //------------------------------------------------------------------------------ 24 // Backend Destroy 25 //------------------------------------------------------------------------------ 26 static int CeedDestroy_Opt(Ceed ceed) { 27 int ierr; 28 Ceed_Opt *data; 29 ierr = CeedGetData(ceed, &data); CeedChkBackend(ierr); 30 ierr = CeedFree(&data); CeedChkBackend(ierr); 31 32 return CEED_ERROR_SUCCESS; 33 } 34 35 //------------------------------------------------------------------------------ 36 // Backend Init 37 //------------------------------------------------------------------------------ 38 static int CeedInit_Opt_Serial(const char *resource, Ceed ceed) { 39 int ierr; 40 if (strcmp(resource, "/cpu/self") 41 && strcmp(resource, "/cpu/self/opt/serial")) 42 // LCOV_EXCL_START 43 return CeedError(ceed, CEED_ERROR_BACKEND, 44 "Opt backend cannot use resource: %s", resource); 45 // LCOV_EXCL_STOP 46 ierr = CeedSetDeterministic(ceed, true); CeedChkBackend(ierr); 47 48 // Create reference CEED that implementation will be dispatched 49 // through unless overridden 50 Ceed ceed_ref; 51 CeedInit("/cpu/self/ref/serial", &ceed_ref); 52 ierr = CeedSetDelegate(ceed, ceed_ref); CeedChkBackend(ierr); 53 54 // Set fallback CEED resource for advanced operator functionality 55 const char fallbackresource[] = "/cpu/self/ref/serial"; 56 ierr = CeedSetOperatorFallbackResource(ceed, fallbackresource); 57 CeedChkBackend(ierr); 58 59 ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "Destroy", 60 CeedDestroy_Opt); CeedChkBackend(ierr); 61 ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "OperatorCreate", 62 CeedOperatorCreate_Opt); CeedChkBackend(ierr); 63 64 // Set blocksize 65 Ceed_Opt *data; 66 ierr = CeedCalloc(1, &data); CeedChkBackend(ierr); 67 data->blk_size = 1; 68 ierr = CeedSetData(ceed, data); CeedChkBackend(ierr); 69 70 return CEED_ERROR_SUCCESS; 71 } 72 73 //------------------------------------------------------------------------------ 74 // Backend Register 75 //------------------------------------------------------------------------------ 76 CEED_INTERN int CeedRegister_Opt_Serial(void) { 77 return CeedRegister("/cpu/self/opt/serial", CeedInit_Opt_Serial, 45); 78 } 79 80 //------------------------------------------------------------------------------ 81