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-ref.h" 18 19 int CeedTensorContractApply_Ref(CeedTensorContract contract, CeedInt A, 20 CeedInt B, CeedInt C, CeedInt J, 21 const CeedScalar *restrict t, 22 CeedTransposeMode tmode, const CeedInt Add, 23 const CeedScalar *restrict u, 24 CeedScalar *restrict v) { 25 CeedInt tstride0 = B, tstride1 = 1; 26 if (tmode == CEED_TRANSPOSE) { 27 tstride0 = 1; tstride1 = J; 28 } 29 30 if (!Add) 31 for (CeedInt q=0; q<A*J*C; q++) 32 v[q] = (CeedScalar) 0.0; 33 34 for (CeedInt a=0; a<A; a++) 35 for (CeedInt b=0; b<B; b++) 36 for (CeedInt j=0; j<J; j++) { 37 CeedScalar tq = t[j*tstride0 + b*tstride1]; 38 for (CeedInt c=0; c<C; c++) 39 v[(a*J+j)*C+c] += tq * u[(a*B+b)*C+c]; 40 } 41 return 0; 42 } 43 44 static int CeedTensorContractDestroy_Ref(CeedTensorContract contract) { 45 return 0; 46 } 47 48 int CeedTensorContractCreate_Ref(CeedBasis basis, CeedTensorContract contract) { 49 int ierr; 50 Ceed ceed; 51 ierr = CeedTensorContractGetCeed(contract, &ceed); CeedChk(ierr); 52 53 ierr = CeedSetBackendFunction(ceed, "TensorContract", contract, "Apply", 54 CeedTensorContractApply_Ref); CeedChk(ierr); 55 ierr = CeedSetBackendFunction(ceed, "TensorContract", contract, "Destroy", 56 CeedTensorContractDestroy_Ref); CeedChk(ierr); 57 58 return 0; 59 } 60