Skip to content

Instantly share code, notes, and snippets.

@pydemo
pydemo / schedile_types.md
Last active September 12, 2018 15:22
OpenPM prange schedule in Cython

static

Iterations are assigned to threads in a fixed way at compile time. If chunksize is not given, the iterations are distributed in num_threads contiguous blocks, one block per thread. If chunksize is given, each chunk is assigned to threads in a round-robin fashion. This is best when the work is evenly distributed and generally known ahead of time.

dynamic

Threads ask the scheduler for the next chunk dynamically at runtime. The chunksize defaults to 1. A dynamic schedule is best when the workload is unevenly distributed and unknown ahead of time.

guided

Chunks are distributed dynamically, like with dynamic. Unlike with dynamic, the chunksize is not fixed but rather is proportional to the remaining iterations divided by the number of threads.

runtime

The schedule and chunksize are determined by either the openmp.openmp_set_schedule function or the OMP_SCHEDULE environment variable at runtime. This allows exploration of different schedules and chunksizes without recompiling, but may have poorer

@pydemo
pydemo / test.md
Last active September 13, 2018 15:34
Timing Python code
>>> result = timeit.repeat('a=list(range(1000000))',number=10, repeat=3)
>>> result
[0.3211609296712368, 0.32038226925490676, 0.31554471308501775]
>>>
@pydemo
pydemo / mymodule.py
Created September 13, 2018 18:24
Testing Python code using pytest
import time
class MyClass:
def __init__(self, input):
self.input = input
def MyMethod(self, dt):
time.sleep(0.1)
@pydemo
pydemo / mymodule.py
Last active September 14, 2018 19:01
Using line_profiler in Python
import time
class MyClass:
def __init__(self, input):
self.input = input
@profile
def MyMethod(self, dt):
time.sleep(0.2)
self.call1()
self.call2()
@pydemo
pydemo / mem_profiled.py
Last active September 14, 2018 18:46
Using memory_profiler in Python
@profile
def benchmark_memory():
sum=0
a=[]
for n in list(range(100000)):
sum +=1
a.append(n)
if __name__ == '__main__':
@pydemo
pydemo / bisect.md
Last active September 14, 2018 20:09
timings for different operations on a list

The bisect module allows fast searches on sorted arrays.

import  bisect
collection = [1, 2, 4, 5, 6]
bisect.bisect(collection, 3)
# Result: 2

This function uses the binary search algorithm that has O(log(N)) running time.

@pydemo
pydemo / robo.md
Created September 14, 2018 20:30
Block robocallers

dial *69 or *57 after robo call.

@pydemo
pydemo / measurements.md
Last active September 15, 2018 22:34
Measurement types

inch- last joint of the thumb yard-from nose to fingers fathom-2 yards cubit - elbow to fingertips digit - one finger width palm - 4 fingers hand- 5 fingers

Distance

@pydemo
pydemo / LOCK.md
Last active September 18, 2018 13:58
Get table info in Redshift

LOCK

An explicit table lock created by one user temporarily prevents another user from selecting data from that table or loading data into it.

Some DDL operations, such as DROP TABLE and TRUNCATE, create exclusive locks. These operations prevent data reads.

If a lock conflict occurs, Amazon Redshift displays an error message to alert the user who started the transaction in conflict. The transaction that received the lock conflict is aborted. Every time a lock conflict occurs, Amazon Redshift writes an entry to the STL_TR_CONFLICT table

@pydemo
pydemo / heaps.md
Last active September 18, 2018 16:07
List counter example

Heaps

Heaps are data structures designed to quickly find and extract the maximum (or minimum) value in a collection.