Skip to content

Commit

Permalink
Final stylization
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenrbrandt committed Apr 28, 2021
1 parent e3b2a72 commit 93244d9
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 6 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ COPY clangmi.cpp .
COPY clangmi.cppm .
COPY clangmipy11.cpp .
COPY Seg.hpp .

# Copying this header makes a minor fix to suppress a warning message.
COPY runtime_support.hpp /usr/local/include/hpx/runtime/components/server/

RUN useradd -m jovyan
Expand All @@ -30,8 +32,11 @@ COPY --chown=jovyan cppnow2021.ipynb /home/jovyan/

RUN mkdir -p /home/jovyan/images
COPY --chown=jovyan cppnow.png /home/jovyan/images
COPY runtime_support.hpp /usr/local/include/hpx/runtime/components/server/runtime_support.hpp
USER jovyan
WORKDIR /home/jovyan
ENV PYTHONPATH /usr/local/python
RUN pip3 install --user jupyterthemes
RUN /home/jovyan/.local/bin/jt -t solarizedl -tfs 15 -fs 15 -ofs 15 -cellw 100%

CMD jupyter notebook --ip 0.0.0.0 --port $PORT
170 changes: 166 additions & 4 deletions cppnow2021.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"id": "71d92085",
"metadata": {},
"source": [
"<img src=\"files/images/cppnow.png\" alt=\"C++ Now Logo\">\n",
"<h1>Interactive C++ in a Jupyter Notebook Using Modules for Incremental Compilation</h1>"
"<img width=100% src=\"files/images/cppnow.png\" alt=\"C++ Now Title Slide\">"
]
},
{
Expand All @@ -17,9 +16,9 @@
"## Once Upon a Time...\n",
"* A colleague and I wanted to teach C++\n",
"* We wanted to make it easier to get started, so we used\n",
" - Docker (a container environment that leverages the kernel)\n",
" - Cling (an Iterpreted version of Clang)\n",
" - Cling (an Interpreted version of Clang)\n",
" - Jupyter/JupyterHub\n",
" - Docker (a container environment that leverages the kernel)\n",
"* We created a tool called C++Explorer for teaching C++(https://github.com/stevenrbrandt/CxxExplorer). But this talk isn't about that..."
]
},
Expand All @@ -46,6 +45,29 @@
"* Through \"magicks,\" i.e. cells beginning with %%, a cell may do something other than a Python command."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2f70588e",
"metadata": {},
"outputs": [],
"source": [
"from IPython.core.magic import register_cell_magic\n",
"@register_cell_magic\n",
"def bash(line, cell): get_ipython().system(cell)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9c96ac93",
"metadata": {},
"outputs": [],
"source": [
"%%bash\n",
"echo Hello, world!"
]
},
{
"cell_type": "markdown",
"id": "6c0d7200",
Expand Down Expand Up @@ -111,6 +133,70 @@
"* works well most of the time"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0905ff5e",
"metadata": {},
"outputs": [],
"source": [
"%%writefile aloha.cppm\n",
"export module aloha;\n",
"#include <iostream>\n",
"export {\n",
" void aloha_world() {\n",
" std::cout << \"Aloha, world!\" << std::endl;\n",
" }\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "442e0691",
"metadata": {},
"outputs": [],
"source": [
"%%bash\n",
"rm -f aloha.pcm aloha.o\n",
"clang++ -std=c++2a -fmodules-ts \\\n",
" --precompile -x c++-module -c aloha.cppm \\\n",
" -fimplicit-modules -fimplicit-module-maps \\\n",
" -stdlib=libc++ # create .pcm file\n",
"clang++ -std=c++2a -fmodules-ts -c aloha.cppm \\\n",
" -fimplicit-modules -fimplicit-module-maps \\\n",
" -stdlib=libc++ # create .o file"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8d102c41",
"metadata": {},
"outputs": [],
"source": [
"%%writefile aloha.cpp\n",
"import aloha;\n",
"\n",
"int main() {\n",
" aloha_world();\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "22edd4ad",
"metadata": {},
"outputs": [],
"source": [
"%%bash\n",
"clang++ -std=c++2a -fmodules-ts -o aloha aloha.cpp \\\n",
" aloha.o -fimplicit-modules -fimplicit-module-maps \\\n",
" -stdlib=libc++ -fmodule-file=aloha.pcm\n",
"./aloha"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -622,6 +708,82 @@
"std::cout << a.get() << std::endl;"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c2e68f30",
"metadata": {},
"outputs": [],
"source": [
"%%def_code\n",
"import <vector>;\n",
"std::vector<int> v = { 1, 2, 3, 4, 5, 6 };"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0df0e9f8",
"metadata": {},
"outputs": [],
"source": [
"# Set the parallelism for HPX\n",
"runcode.runflags = [\"-t\",\"4\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "067a34a1",
"metadata": {},
"outputs": [],
"source": [
"%%run_code\n",
"\n",
"#include <hpx/hpx_main.hpp>\n",
"#include <hpx/algorithm.hpp>\n",
"#include <hpx/execution.hpp>\n",
"\n",
"hpx::for_loop(\n",
" hpx::execution::par, 0, v.size(),\n",
" [](std::size_t n) { std::cout << \"n=\" << n << std::endl;});"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aa94cf77",
"metadata": {},
"outputs": [],
"source": [
"%%run_code\n",
"#include <hpx/hpx.hpp>\n",
"#include <hpx/hpx_main.hpp>\n",
"\n",
"auto result1 = [](){ return 41; };\n",
"auto result2 = [](hpx::future<int> s){ return 1+s.get(); };\n",
"\n",
"hpx::future<int> t = hpx::async(result1);\n",
"hpx::future<int> t2 = t.then(result2);\n",
"std::cout << t2.get() << std::endl;"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f75c0dcd",
"metadata": {},
"outputs": [],
"source": [
"%%run_code\n",
"#include <hpx/hpx_main.hpp>\n",
"#include <hpx/parallel/algorithms/reverse.hpp>\n",
"hpx::parallel::reverse(hpx::execution::par,\n",
" v.begin(),v.end());\n",
"for(auto i = v.begin(); i != v.end(); ++i)\n",
" std::cout << *i << std::endl;"
]
},
{
"cell_type": "markdown",
"id": "identified-return",
Expand Down
3 changes: 2 additions & 1 deletion runcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def register_cell_magic(x):
verbosity = 0
appflags = []
modflags = []
runflags = []
cxx_std = "-std=c++2a"

def expand_flags(line):
Expand Down Expand Up @@ -240,7 +241,7 @@ def run_code_(line, code):
r = run_cmd(cmd)
t2 = time()
if r == 0:
run_cmd(["./exec_step_%s" % session])
run_cmd(["./exec_step_%s" % session]+runflags)
t3 = time()
print(colored("compile time: %.2f" % (t2-t1),"green"))
print(colored("run time: %.2f" % (t3-t2),"green"))
Expand Down
3 changes: 2 additions & 1 deletion runtime_support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
#include <hpx/synchronization/condition_variable.hpp>
#include <hpx/synchronization/mutex.hpp>
#include <hpx/synchronization/spinlock.hpp>
#include <hpx/traits/action_does_termination_detection.hpp>
//#include <hpx/traits/action_does_termination_detection.hpp>
#include <hpx/modules/actions_base.hpp>

#include <atomic>
#include <condition_variable>
Expand Down

0 comments on commit 93244d9

Please sign in to comment.