xref: /libCEED/examples/python/tutorial-0-ceed.ipynb (revision 7fcac03628df7c326a56de618266f195cb34c506)
1{
2 "cells": [
3  {
4   "cell_type": "markdown",
5   "metadata": {},
6   "source": [
7    "# libCEED for Python examples\n",
8    "\n",
9    "This is a tutorial to illustrate the main feautures of the Python interface for [libCEED](https://github.com/CEED/libCEED/), the low-level API library for efficient high-order discretization methods developed by the co-design [Center for Efficient Exascale Discretizations](https://ceed.exascaleproject.org/) (CEED) of the [Exascale Computing Project](https://www.exascaleproject.org/) (ECP).\n",
10    "\n",
11    "While libCEED's focus is on high-order finite/spectral element method implementations, the approach is mostly algebraic and thus applicable to other discretizations in factored form, as explained in the [user manual](https://libceed.readthedocs.io/)."
12   ]
13  },
14  {
15   "cell_type": "markdown",
16   "metadata": {},
17   "source": [
18    "## Setting up libCEED for Python"
19   ]
20  },
21  {
22   "cell_type": "markdown",
23   "metadata": {},
24   "source": [
25    "Install libCEED for Python by running"
26   ]
27  },
28  {
29   "cell_type": "code",
30   "execution_count": null,
31   "metadata": {},
32   "outputs": [],
33   "source": [
34    "! python -m pip install libceed"
35   ]
36  },
37  {
38   "cell_type": "markdown",
39   "metadata": {},
40   "source": [
41    "## Ceed\n",
42    "\n",
43    "Here we show some basic examples to illustrate the `Ceed` class. In libCEED, Ceeds represent library context representing control of logical hardware resources.\n",
44    "\n",
45    "Here we illustrate the simple declaration of a `Ceed`, with default resource (which is `/cpu/self`)"
46   ]
47  },
48  {
49   "cell_type": "code",
50   "execution_count": null,
51   "metadata": {},
52   "outputs": [],
53   "source": [
54    "import libceed\n",
55    "\n",
56    "ceed = libceed.Ceed()"
57   ]
58  },
59  {
60   "cell_type": "markdown",
61   "metadata": {},
62   "source": [
63    "You can visualize the memory address of the object instantiated by typing"
64   ]
65  },
66  {
67   "cell_type": "code",
68   "execution_count": null,
69   "metadata": {},
70   "outputs": [],
71   "source": [
72    "print(ceed)"
73   ]
74  },
75  {
76   "cell_type": "markdown",
77   "metadata": {},
78   "source": [
79    "To use a particular backend, for instance `/cpu/self/opt/blocked` you can specify"
80   ]
81  },
82  {
83   "cell_type": "code",
84   "execution_count": null,
85   "metadata": {},
86   "outputs": [],
87   "source": [
88    "ceed = libceed.Ceed('/cpu/self/opt/blocked')"
89   ]
90  },
91  {
92   "cell_type": "markdown",
93   "metadata": {},
94   "source": [
95    "Similarly, if libCEED is built with GPU support, you can specify a GPU backend, e.g., `/gpu/occa` or `/gpu/cuda/gen`."
96   ]
97  }
98 ],
99 "metadata": {
100  "kernelspec": {
101   "display_name": "Python 3",
102   "language": "python",
103   "name": "python3"
104  },
105  "language_info": {
106   "codemirror_mode": {
107    "name": "ipython",
108    "version": 3
109   },
110   "file_extension": ".py",
111   "mimetype": "text/x-python",
112   "name": "python",
113   "nbconvert_exporter": "python",
114   "pygments_lexer": "ipython3",
115   "version": "3.8.5"
116  }
117 },
118 "nbformat": 4,
119 "nbformat_minor": 4
120}
121