xref: /libCEED/README.md (revision 91cbf07c0012a20575aa9d4df35815b885253099)
1# libCEED: the CEED API Library
2
3[![Build Status](https://travis-ci.org/CEED/libCEED.svg?branch=master)](https://travis-ci.org/CEED/libCEED)
4[![Code Coverage](https://codecov.io/gh/CEED/libCEED/branch/master/graphs/badge.svg)](https://codecov.io/gh/CEED/libCEED/)
5[![License](https://img.shields.io/badge/License-BSD%202--Clause-orange.svg)](https://opensource.org/licenses/BSD-2-Clause)
6[![Doxygen](https://codedocs.xyz/CEED/libCEED.svg)](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
60The library attempts to automatically detect support for the AVX
61instruction set using gcc-style compiler options for the host.
62Support may need to be manually specified via
63
64    make AVX=1
65
66or
67
68    make AVX=0
69
70if your compiler does not support gcc-style options, if you are cross
71compiling, etc.
72
73## Testing
74
75The test suite produces [TAP](https://testanything.org) output and is run by:
76
77    make test
78
79or, using the `prove` tool distributed with Perl (recommended)
80
81    make prove
82
83## Examples
84
85libCEED comes with several examples of its usage, ranging from standalone C
86codes in the `/examples/ceed` directory to examples based on external packages,
87such as MFEM, PETSc and Nek5000.
88
89To build the examples, set the `MFEM_DIR`, `PETSC_DIR` and `NEK5K_DIR` variables
90and run:
91
92```console
93# libCEED examples on CPU and GPU
94cd examples/ceed
95make
96./ex1 -ceed /cpu/self
97./ex1 -ceed /gpu/occa
98cd ../..
99
100# MFEM+libCEED examples on CPU and GPU
101cd examples/mfem
102make
103./bp1 -ceed /cpu/self -no-vis
104./bp1 -ceed /gpu/occa -no-vis
105cd ../..
106
107# PETSc+libCEED examples on CPU and GPU
108cd examples/petsc
109make
110./bp1 -ceed /cpu/self
111./bp1 -ceed /gpu/occa
112cd ../..
113
114# Nek+libCEED examples on CPU and GPU
115cd examples/nek5000
116./make-nek-examples.sh
117./run-nek-example.sh -ceed /cpu/self -b 3
118./run-nek-example.sh -ceed /gpu/occa -b 3
119cd ../..
120```
121
122The above code assumes a GPU-capable machine enabled in the OCCA
123backend. Depending on the available backends, other Ceed resource specifiers can
124be provided with the `-ceed` option, for example:
125
126|  CEED resource (`-ceed`) | Backend                                           |
127| :----------------------- | :------------------------------------------------ |
128| `/cpu/self/ref`          | Serial reference implementation                   |
129| `/cpu/self/blocked`      | Serial blocked implementation                     |
130| `/cpu/self/tmpl`         | Backend template, dispatches to /cpu/self/blocked |
131| `/cpu/self/avx`          | Vectorized blocked implementation                 |
132| `/cpu/self/xsmm/serial`  | Serial LIBXSMM implementation                     |
133| `/cpu/self/xsmm/blocked` | Blocked LIBXSMM implementation                    |
134| `/cpu/occa`              | Serial OCCA kernels                               |
135| `/gpu/occa`              | CUDA OCCA kernels                                 |
136| `/omp/occa`              | OpenMP OCCA kernels                               |
137| `/ocl/occa`              | OpenCL OCCA kernels                               |
138| `/gpu/magma`             | CUDA MAGMA kernels                                |
139
140
141## Benchmarks
142
143A sequence of benchmarks for all enabled backends can be run using
144
145```console
146make benchmarks
147```
148
149The results from the benchmarks are stored inside the `benchmarks/` directory
150and they can be viewed using the commands (requires python with matplotlib):
151
152```console
153cd benchmarks
154python postprocess-plot.py petsc-bp1-*-output.txt
155python postprocess-plot.py petsc-bp3-*-output.txt
156```
157
158Using the `benchmarks` target runs a comprehensive set of benchmarks which may
159take some time to run. Subsets of the benchmarks can be run using targets such
160as `make bench-petsc-bp1`, or `make bench-petsc-bp3`.
161
162For more details about the benchmarks, see
163[`benchmarks/README.md`](benchmarks/README.md)
164
165
166## Install
167
168To install libCEED, run
169
170    make install prefix=/usr/local
171
172or (e.g., if creating packages),
173
174    make install prefix=/usr DESTDIR=/packaging/path
175
176Note that along with the library, libCEED installs kernel sources, e.g. OCCA
177kernels are installed in `$prefix/lib/okl`. This allows the OCCA backend to
178build specialized kernels at run-time. In a normal setting, the kernel sources
179will be found automatically (relative to the library file `libceed.so`).
180However, if that fails (e.g. if `libceed.so` is moved), one can copy (cache) the
181kernel sources inside the user OCCA directory, `~/.occa` using
182
183    $(OCCA_DIR)/bin/occa cache ceed $(CEED_DIR)/lib/okl/*.okl
184
185This will allow OCCA to find the sources regardless of the location of the CEED
186library. One may occasionally need to clear the OCCA cache, which can be accomplished
187by removing the `~/.occa` directory or by calling `$(OCCA_DIR)/bin/occa clear -a`.
188
189### pkg-config
190
191In addition to library and header, libCEED provides a [pkg-config][pkg-config1]
192file that can be used to easily compile and link. [For example][pkg-config2], if
193`$prefix` is a standard location or you set the environment variable
194`PKG_CONFIG_PATH`,
195
196    cc `pkg-config --cflags --libs ceed` -o myapp myapp.c
197
198will build `myapp` with libCEED.  This can be used with the source or
199installed directories.  Most build systems have support for pkg-config.
200
201## Contact
202
203You can reach the libCEED team by emailing [ceed-users@llnl.gov](mailto:ceed-users@llnl.gov)
204or by leaving a comment in the [issue tracker](https://github.com/CEED/libCEED/issues).
205
206## Copyright
207
208The following copyright applies to each file in the CEED software suite, unless
209otherwise stated in the file:
210
211> Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at the
212> Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights reserved.
213
214See files LICENSE and NOTICE for details.
215
216[ceed-soft]:   http://ceed.exascaleproject.org/software/
217[ecp]:         https://exascaleproject.org/exascale-computing-project
218[pkg-config1]: https://en.wikipedia.org/wiki/Pkg-config
219[pkg-config2]: https://people.freedesktop.org/~dbn/pkg-config-guide.html#faq
220