xref: /libCEED/examples/python/tutorial-0-ceed.ipynb (revision 6261a418bdb3efd56d67795785948f0f7b436c3e)
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.org/)."
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/hip` or `/gpu/cuda/gen`."
96   ]
97  },
98  {
99   "cell_type": "code",
100   "execution_count": null,
101   "metadata": {},
102   "outputs": [],
103   "source": []
104  }
105 ],
106 "metadata": {
107  "kernelspec": {
108   "display_name": "Python 3",
109   "language": "python",
110   "name": "python3"
111  },
112  "language_info": {
113   "codemirror_mode": {
114    "name": "ipython",
115    "version": 3
116   },
117   "file_extension": ".py",
118   "mimetype": "text/x-python",
119   "name": "python",
120   "nbconvert_exporter": "python",
121   "pygments_lexer": "ipython3",
122   "version": "3.8.5"
123  }
124 },
125 "nbformat": 4,
126 "nbformat_minor": 4
127}
128