1# libCEED: the CEED API Library 2 3[](https://travis-ci.org/CEED/libCEED) 4[](https://codecov.io/gh/CEED/libCEED/) 5[](https://opensource.org/licenses/BSD-2-Clause) 6[](https://codedocs.xyz/CEED/libCEED/) 7 8## Code for Efficient Extensible Discretization 9 10This repository contains an initial low-level API library for the efficient 11high-order discretization methods developed by the ECP co-design [Center for 12Efficient Exascale Discretizations (CEED)](http://ceed.exascaleproject.org). 13While our focus is on high-order finite elements, the approach is mostly 14algebraic and thus applicable to other discretizations in factored form, as 15explained in the API documentation portion of the [Doxygen documentation](https://codedocs.xyz/CEED/libCEED/md_doc_libCEEDapi.html). 16 17One of the challenges with high-order methods is that a global sparse matrix is 18no longer a good representation of a high-order linear operator, both with 19respect to the FLOPs needed for its evaluation, as well as the memory transfer 20needed for a matvec. Thus, high-order methods require a new "format" that still 21represents a linear (or more generally non-linear) operator, but not through a 22sparse matrix. 23 24The goal of libCEED is to propose such a format, as well as supporting 25implementations and data structures, that enable efficient operator evaluation 26on a variety of computational device types (CPUs, GPUs, etc.). This new operator 27description is based on algebraically [factored form](https://codedocs.xyz/CEED/libCEED/md_doc_libCEEDapi.html), 28which is easy to incorporate in a wide variety of applications, without significant 29refactoring of their own discretization infrastructure. 30 31The repository is part of the [CEED software suite][ceed-soft], a collection of 32software benchmarks, miniapps, libraries and APIs for efficient exascale 33discretizations based on high-order finite element and spectral element methods. 34See http://github.com/ceed for more information and source code availability. 35 36The CEED research is supported by the [Exascale Computing Project][ecp] 37(17-SC-20-SC), a collaborative effort of two U.S. Department of Energy 38organizations (Office of Science and the National Nuclear Security 39Administration) responsible for the planning and preparation of a [capable 40exascale ecosystem](https://exascaleproject.org/what-is-exascale), including 41software, applications, hardware, advanced system engineering and early testbed 42platforms, in support of the nation’s exascale computing imperative. 43 44For more details on the CEED API see http://ceed.exascaleproject.org/ceed-code/. 45 46## Building 47 48The CEED library, `libceed`, is a C99 library with no external dependencies. It 49can be built using 50 51 make 52 53or, with optimization flags 54 55 make OPT='-O3 -march=skylake-avx512 -ffp-contract=fast' 56 57These optimization flags are used by all languages (C, C++, Fortran) and this 58makefile variable can also be set for testing and examples (below). 59 60## Testing 61 62The test suite produces [TAP](https://testanything.org) output and is run by: 63 64 make test 65 66or, using the `prove` tool distributed with Perl (recommended) 67 68 make prove 69 70## Examples 71 72libCEED comes with several examples of its usage, ranging from standalone C 73codes in the `/examples/ceed` directory to examples based on external packages, 74such as MFEM, PETSc and Nek5000. 75 76To build the examples, set the `MFEM_DIR`, `PETSC_DIR` and `NEK5K_DIR` variables 77and run: 78 79```console 80# libCEED examples on CPU and GPU 81cd examples/ceed 82make 83./ex1 -ceed /cpu/self 84./ex1 -ceed /gpu/occa 85cd ../.. 86 87# MFEM+libCEED examples on CPU and GPU 88cd examples/mfem 89make 90./bp1 -ceed /cpu/self -no-vis 91./bp1 -ceed /gpu/occa -no-vis 92cd ../.. 93 94# PETSc+libCEED examples on CPU and GPU 95cd examples/petsc 96make 97./bp1 -ceed /cpu/self 98./bp1 -ceed /gpu/occa 99cd ../.. 100 101# Nek+libCEED examples on CPU and GPU 102cd examples/nek5000 103./make-nek-examples.sh 104./run-nek-example.sh -ceed /cpu/self -b 3 105./run-nek-example.sh -ceed /gpu/occa -b 3 106cd ../.. 107``` 108 109The above code assumes a GPU-capable machine enabled in the OCCA 110backend. Depending on the available backends, other Ceed resource specifiers can 111be provided with the `-ceed` option, for example: 112 113| CEED resource (`-ceed`) | Backend | 114| :----------------------- | :-------------------------------------------- | 115| `/cpu/self/opt` | Serial optimized implementation | 116| `/cpu/self/ref` | Serial reference implementation | 117| `/cpu/self/tmpl` | Backend template, dispatches to /cpu/self/opt | 118| `/cpu/occa` | Serial OCCA kernels | 119| `/gpu/occa` | CUDA OCCA kernels | 120| `/omp/occa` | OpenMP OCCA kernels | 121| `/ocl/occa` | OpenCL OCCA kernels | 122| `/gpu/magma` | CUDA MAGMA kernels | 123 124## Install 125 126To install libCEED, run 127 128 make install prefix=/usr/local 129 130or (e.g., if creating packages), 131 132 make install prefix=/usr DESTDIR=/packaging/path 133 134Note that along with the library, libCEED installs kernel sources, e.g. OCCA 135kernels are installed in `$prefix/lib/okl`. This allows the OCCA backend to 136build specialized kernels at run-time. In a normal setting, the kernel sources 137will be found automatically (relative to the library file `libceed.so`). 138However, if that fails (e.g. if `libceed.so` is moved), one can copy (cache) the 139kernel sources inside the user OCCA directory, `~/.occa` using 140 141 $(OCCA_DIR)/bin/occa cache ceed $(CEED_DIR)/lib/okl/*.okl 142 143This will allow OCCA to find the sources regardless of the location of the CEED 144library. One may occasionally need to clear the OCCA cache, which can be accomplished 145by removing the `~/.occa` directory or by calling `$(OCCA_DIR)/bin/occa clear -a`. 146 147### pkg-config 148 149In addition to library and header, libCEED provides a [pkg-config][pkg-config1] 150file that can be used to easily compile and link. [For example][pkg-config2], if 151`$prefix` is a standard location or you set the environment variable 152`PKG_CONFIG_PATH`, 153 154 cc `pkg-config --cflags --libs ceed` -o myapp myapp.c 155 156will build `myapp` with libCEED. This can be used with the source or 157installed directories. Most build systems have support for pkg-config. 158 159## Contact 160 161You can reach the libCEED team by emailing [ceed-users@llnl.gov](mailto:ceed-users@llnl.gov) 162or by leaving a comment in the [issue tracker](https://github.com/CEED/libCEED/issues). 163 164## Copyright 165 166The following copyright applies to each file in the CEED software suite, unless 167otherwise stated in the file: 168 169> Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at the 170> Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights reserved. 171 172See files LICENSE and NOTICE for details. 173 174[ceed-soft]: http://ceed.exascaleproject.org/software/ 175[ecp]: https://exascaleproject.org/exascale-computing-project 176[pkg-config1]: https://en.wikipedia.org/wiki/Pkg-config 177[pkg-config2]: https://people.freedesktop.org/~dbn/pkg-config-guide.html#faq 178