Skip to content

Commit

Permalink
Add a better python example. Tweek performance
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Hursey <[email protected]>
  • Loading branch information
jjhursey committed Nov 6, 2020
1 parent a809a6a commit 5eb9a4a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 18 deletions.
47 changes: 32 additions & 15 deletions pmix.sty
Original file line number Diff line number Diff line change
Expand Up @@ -769,19 +769,36 @@
% Ubuntu:
% sudo apt update
% sudo apt install python-pip
%
% package to work around "No room for a new \write" message
\usepackage{morewrites}
\usepackage{minted}
\morewritessetup{allocate=10}
% package for code highlighting
\usepackage[chapter]{minted}
\usemintedstyle{default}
\usepackage{xcolor}

% Background: Light Gray
\definecolor{pmixbg}{rgb}{0.95,0.95,0.95}
% Highlight: Yellow
\definecolor{pmixhl}{rgb}{0.95,0.95,0}
% C Code block

%-----------------------
% C Code
%
% block of code
% \begin{pmixCodeC}
% return 0;
% \end{pmixCodeC}
%
% Inline C code
% The code \pmixCodeInlineC{printf("Hello World");} prints ``Hello World''.
%
% Import C code from a file:
% - Whole file: \pmixCodeImportC{sources/hello.c}
% - Selection of a file: \pmixCodeImportC[firstline=73, lastline=84]{sources/hello.c}
% - Highlight selection of a file: \pmixCodeImportC[firstline=73, lastline=84, highlightlines={2-4,6}]{sources/hello.c}
%
\newminted[pmixCodeC]{c}{fontsize=\small,
bgcolor=pmixbg,
highlightcolor=pmixhl,
Expand All @@ -790,18 +807,12 @@
linenos,
numbersep=3pt,
firstnumber=1}
% Inline C code
% The code \pmixCodeInlineC{printf("Hello World");} prints ``Hello World''.
\newmintinline[pmixCodeInlineC]{c}{bgcolor=pmixbg,
highlightcolor=pmixhl,
breaklines,
autogobble,
linenos,
firstnumber=1}
% Import C code from a file:
% - Whole file: \pmixCodeImportC{sources/hello.c}
% - Selection of a file: \pmixCodeImportC[firstline=73, lastline=84]{sources/hello.c}
% - Highlight selection of a file: \pmixCodeImportC[firstline=73, lastline=84, highlightlines={2-4,6}]{sources/hello.c}
\newmintedfile[pmixCodeImportC]{c}{fontsize=\small,
bgcolor=pmixbg,
highlightcolor=pmixhl,
Expand All @@ -811,10 +822,22 @@
numbersep=3pt,
firstnumber=1}

% Python Code block
%-----------------------
% Python Code
%
% block of code
% \begin{pmixCodePy}
% print("Hello")
% \end{pmixCodePy}
%
% Inline C code
% The code \pmixCodeInlinePy{print("Hello World")} prints ``Hello World''.
%
% Import C code from a file:
% - Whole file: \pmixCodeImportPy{sources/hello.py}
% - Selection of a file: \pmixCodeImportPy[firstline=73, lastline=84]{sources/hello.py}
% - Highlight selection of a file: \pmixCodeImportPy[firstline=73, lastline=84, highlightlines={2-4,6}]{sources/hello.py}
%
\newminted[pmixCodepPy]{python}{fontsize=\small,
bgcolor=pmixbg,
highlightcolor=pmixhl,
Expand All @@ -823,18 +846,12 @@
linenos,
numbersep=3pt,
firstnumber=1}
% Inline C code
% The code \pmixCodeInlinePy{print("Hello World")} prints ``Hello World''.
\newmintinline[pmixCodeInlinePy]{python}{bgcolor=pmixbg,
highlightcolor=pmixhl,
breaklines,
autogobble,
linenos,
firstnumber=1}
% Import C code from a file:
% - Whole file: \pmixCodeImportPy{sources/hello.py}
% - Selection of a file: \pmixCodeImportPy[firstline=73, lastline=84]{sources/hello.py}
% - Highlight selection of a file: \pmixCodeImportPy[firstline=73, lastline=84, highlightlines={2-4,6}]{sources/hello.py}
\newmintedfile[pmixCodeImportPy]{python}{fontsize=\small,
bgcolor=pmixbg,
highlightcolor=pmixhl,
Expand Down
33 changes: 30 additions & 3 deletions sources/hello.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
#<EG BEGIN ID="pmix_py">
print("Hello World")
#<EG END ID="pmix_py">
#!/usr/bin/env python3

from pmix import *

def main():
#<EG BEGIN ID="pmix_init">
client_hdl = PMIxClient()
#<EG END ID="pmix_init">
print("Testing PMIx ", client_hdl.get_version())

print("Init")
#<EG BEGIN ID="pmix_init">
info = []
(rc,myproc) = client_hdl.init(info)
if 0 != rc:
exit(1)
#<EG END ID="pmix_init">

print("Get")
info = []
rc, get_val = client_hdl.get(myproc, "PMIX_LOCAL_RANK", info)
print("Get result: ", rc)
print("Get value returned: ", get_val)

print("Finalize")
info = []
client_hdl.finalize(info)

if __name__ == '__main__':
main()

0 comments on commit 5eb9a4a

Please sign in to comment.