-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parallel2017 #1
Open
anton-malakhov
wants to merge
7
commits into
master
Choose a base branch
from
parallel2017
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Parallel2017 #1
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e9bee47
new implementations: multiprocessing, ipyparallel, mpi
fschlimb 44746ae
fixed typo
fschlimb 1250817
- renaming files to distinguish between runnable and supporting files
fschlimb dbfc729
adding py3 executor implementations
fschlimb 2eb2d21
added distarray
fschlimb 449d90c
using @syntax
fschlimb 287d9c2
exe slow benches last
fschlimb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import base_bs_erf | ||
import numpy as np | ||
import multiprocessing | ||
import bs_erf_naive | ||
|
||
global bs_impl | ||
global pool | ||
global nump | ||
|
||
|
||
def black_scholes(nopt, price, strike, t, rate, vol): | ||
global bs_impl | ||
global pool | ||
global nump | ||
noptpp = int(nopt/nump) | ||
call = np.empty(nopt, dtype=np.float64) | ||
put = np.empty(nopt, dtype=np.float64) | ||
asyncs = [pool.apply_async(bs_impl, (noptpp, price[i:i+noptpp], strike[i:i+noptpp], t[i:i+noptpp], rate, vol)) for i in range(0, nopt, noptpp)] | ||
for a,i in zip(asyncs, range(len(asyncs))): | ||
call[i:i+noptpp], put[i:i+noptpp] = a.get() | ||
return call, put | ||
|
||
|
||
def main(title, impl, thepool): | ||
global bs_impl | ||
global pool | ||
global nump | ||
bs_impl = impl | ||
nump = multiprocessing.cpu_count() | ||
pool = thepool(nump) | ||
base_bs_erf.run(title, black_scholes, pass_args=False) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import base_bs_erf | ||
import multiprocessing | ||
|
||
global bs_impl | ||
global pool | ||
global nump | ||
|
||
|
||
class bs(object): | ||
def __init__(self, nopt, rate, vol): | ||
self.nopt = nopt | ||
self.rate = rate | ||
self.vol = vol | ||
|
||
def __call__(self, zipped): | ||
return bs_impl(self.nopt, *zipped, self.rate, self.vol) | ||
|
||
|
||
def black_scholes(nopt, price, strike, t, rate, vol): | ||
global bs_impl | ||
global pool | ||
z = list(zip(price, strike, t)) | ||
return pool.map(bs(nopt, rate, vol), z) | ||
|
||
|
||
def main(title, impl, thepool): | ||
global bs_impl | ||
global pool | ||
global nump | ||
bs_impl = impl | ||
nump = multiprocessing.cpu_count() | ||
pool = thepool(nump) | ||
base_bs_erf.run(title, black_scholes, pass_args=False) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import base_bs_erf | ||
import numpy as np | ||
from mpi4py import MPI | ||
|
||
global nump | ||
global bs_impl | ||
|
||
|
||
def black_scholes(nopt, price, strike, t, rate, vol, call, put): | ||
comm = MPI.COMM_WORLD | ||
rank = comm.Get_rank() | ||
noptpp = int(nopt/nump) | ||
|
||
myprice = np.empty(noptpp, dtype=np.float64) | ||
mystrike = np.empty(noptpp, dtype=np.float64) | ||
myt = np.empty(noptpp, dtype=np.float64) | ||
|
||
# Scatter data into arrays | ||
comm.Scatter(price, myprice, root=0) | ||
comm.Scatter(strike, mystrike, root=0) | ||
comm.Scatter(t, myt, root=0) | ||
|
||
mycall, myput = bs_impl(noptpp, myprice, mystrike, myt, rate, vol) | ||
|
||
comm.Gather(mycall, call) | ||
comm.Gather(myput, put) | ||
|
||
return call, put | ||
|
||
|
||
def main(title, impl): | ||
global nump | ||
global bs_impl | ||
nump = MPI.COMM_WORLD.size | ||
bs_impl = impl | ||
base_bs_erf.run(title, black_scholes, pass_args=True, verbose=MPI.COMM_WORLD.Get_rank()==0) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,14 @@ | |
import numpy as np | ||
invsqrt = lambda x: 1.0/sqrt(x) | ||
|
||
def black_scholes ( nopt, price, strike, t, rate, vol, call, put ): | ||
|
||
def black_scholes_args(nopt, price, strike, t, rate, vol, call, put): | ||
mr = -rate | ||
sig_sig_two = vol * vol * 2 | ||
|
||
for i in range(nopt): | ||
P = float( price [i] ) | ||
S = strike [i] | ||
T = t [i] | ||
P = float(price[i]) | ||
S = strike[i] | ||
T = t[i] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spaces here were on purpose to make it look pretty in WinMerge reports comparing implementations |
||
|
||
a = log(P / S) | ||
b = T * mr | ||
|
@@ -27,7 +27,43 @@ def black_scholes ( nopt, price, strike, t, rate, vol, call, put ): | |
|
||
Se = exp(b) * S | ||
|
||
call [i] = P * d1 - Se * d2 | ||
put [i] = call [i] - P + Se | ||
|
||
base_bs_erf.run("Naive-loop", black_scholes, 4, 8, nparr=False, pass_args=True) | ||
call[i] = P * d1 - Se * d2 | ||
put[i] = call[i] - P + Se | ||
return call, put | ||
|
||
|
||
def black_scholes(nopt, price, strike, t, rate, vol): | ||
call = np.zeros(nopt, dtype=np.float64) | ||
put = -np.ones(nopt, dtype=np.float64) | ||
return black_scholes_args(nopt, price, strike, t, rate, vol, call, put) | ||
|
||
|
||
def black_scholes_map(nopt, price, strike, t, rate, vol): | ||
mr = -rate | ||
sig_sig_two = vol * vol * 2 | ||
P = float(price) | ||
S = strike | ||
T = t | ||
|
||
a = log(P / S) | ||
b = T * mr | ||
|
||
z = T * sig_sig_two | ||
c = 0.25 * z | ||
y = invsqrt(z) | ||
|
||
w1 = (a - b + c) * y | ||
w2 = (a - b - c) * y | ||
|
||
d1 = 0.5 + 0.5 * erf(w1) | ||
d2 = 0.5 + 0.5 * erf(w2) | ||
|
||
Se = exp(b) * S | ||
|
||
call = P * d1 - Se * d2 | ||
put = call - P + Se | ||
return call, put | ||
|
||
|
||
if __name__ == '__main__': | ||
base_bs_erf.run(__file__, black_scholes_args, nparr=False, pass_args=True) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from bs_erf_apply import main | ||
from multiprocessing.pool import Pool | ||
from bs_erf_naive import black_scholes | ||
|
||
if __name__ == '__main__': | ||
main(__file__, black_scholes, Pool) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from bs_erf_apply import main | ||
from multiprocessing.pool import ThreadPool | ||
from bs_erf_naive import black_scholes | ||
|
||
if __name__ == '__main__': | ||
main(__file__, black_scholes, ThreadPool) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from bs_erf_map import main | ||
from multiprocessing import Pool | ||
from bs_erf_naive import black_scholes_map | ||
|
||
if __name__ == '__main__': | ||
main(__file__, black_scholes_map, Pool) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from bs_erf_map import main | ||
from multiprocessing.pool import ThreadPool | ||
from bs_erf_naive import black_scholes_map | ||
|
||
if __name__ == '__main__': | ||
main(__file__, black_scholes_map, ThreadPool) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from bs_erf_mpi import main | ||
from bs_erf_naive import black_scholes | ||
|
||
if __name__ == '__main__': | ||
main(__file__, black_scholes) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from bs_erf_naive import black_scholes_args | ||
from bs_erf_threading import main | ||
|
||
if __name__ == '__main__': | ||
main(__file__, black_scholes_args) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's changed here? EOLs?