This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import inspect | |
import cProfile as profile | |
import wrapt | |
def prof(*dec_args, **dec_kwargs): | |
pr = profile.Profile() | |
if not dec_args or not inspect.isfunction(dec_args[0]): | |
@wrapt.decorator | |
def wrapper(wrapped, instance, args, kwargs): | |
pr.enable() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
How to use mpi4py with msgpack serialization | |
""" | |
from mpi4py import MPI | |
import msgpack | |
# mpi4py assumes that the serializer function takes more than one parameter: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Synchronize PUB/SUB sockets. | |
""" | |
import multiprocessing as mp | |
import time | |
import zmq |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Allocate a GPUArray on one GPU in one process and copy it to | |
some other GPU in another process using IPC handles. | |
Notes | |
----- | |
Requires that the two GPUs support peer-to-peer data transfers. | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Demo of how to pass GPU memory managed by pycuda to mpi4py. | |
Notes | |
----- | |
This code can be used to perform peer-to-peer communication of data via | |
NVIDIA's GPUDirect technology if mpi4py has been built against a | |
CUDA-enabled MPI implementation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Exception handler that outputs exception data to twiggy logger. | |
""" | |
import re | |
import sys | |
import traceback | |
import twiggy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Nonblocking file logging handler using ZeroMQ. | |
""" | |
import atexit | |
import collections | |
import logging | |
import multiprocessing as mp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Demo of how to write a property decorator with optional arguments. | |
""" | |
import functools | |
import inspect | |
def myprop(*dec_args): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Demo of how to write a decorator with optional arguments. | |
""" | |
import functools | |
import inspect | |
def mydec(*dec_args, **dec_kwargs): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Demo of how to use function pointers with fused types in Cython: | |
cimport cython | |
ctypedef fused fused_type: | |
cython.double | |
cython.longlong | |
cdef double func0(double x, double y): | |
return x+y |