Skip to content

Instantly share code, notes, and snippets.

View lebedov's full-sized avatar

Lev E. Givon lebedov

View GitHub Profile
@lebedov
lebedov / profile_decorator.py
Created January 2, 2015 15:05
Decorator for profiling functions.
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()
@lebedov
lebedov / mpi4py_msgpack_demo.py
Created December 25, 2014 04:04
How to use mpi4py with msgpack serialization
#!/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:
@lebedov
lebedov / sync_pub_sub.py
Last active August 29, 2015 14:09
ZeroMQ asynchronous socket pair synchronizer.
#!/usr/bin/env python
"""
Synchronize PUB/SUB sockets.
"""
import multiprocessing as mp
import time
import zmq
@lebedov
lebedov / p2p_pycuda_ipc_demo.py
Created October 8, 2014 15:31
Allocate a GPUArray on one GPU in one process and copy it to some other GPU in another process using IPC handles.
#!/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.
"""
@lebedov
lebedov / mpi4py_pycuda_demo.py
Last active December 2, 2022 04:23
Demo of how to pass GPU memory managed by pycuda to mpi4py.
#!/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.
@lebedov
lebedov / twiggy_exception_handler.py
Created September 14, 2014 17:58
Exception handler that outputs exception data to twiggy logger.
#!/usr/bin/env python
"""
Exception handler that outputs exception data to twiggy logger.
"""
import re
import sys
import traceback
import twiggy
@lebedov
lebedov / nbfilehandler.py
Created September 10, 2014 22:24
Nonblocking file logging handler using ZeroMQ.
#!/usr/bin/env python
"""
Nonblocking file logging handler using ZeroMQ.
"""
import atexit
import collections
import logging
import multiprocessing as mp
@lebedov
lebedov / decorate_property_with_args.py
Created August 13, 2014 00:09
Demo of how to write a property decorator with optional arguments.
#!/usr/bin/env python
"""
Demo of how to write a property decorator with optional arguments.
"""
import functools
import inspect
def myprop(*dec_args):
@lebedov
lebedov / decorate_with_args.py
Last active August 29, 2015 14:05
Demo of how to write a decorator with optional arguments.
#!/usr/bin/env python
"""
Demo of how to write a decorator with optional arguments.
"""
import functools
import inspect
def mydec(*dec_args, **dec_kwargs):
@lebedov
lebedov / func_ptr_fused.pyx
Created July 29, 2014 23:20
How to use function pointers with fused types in Cython
# 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