-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New examples and new mapreduce function that uses scatter
- Loading branch information
Darren Govoni
committed
Feb 28, 2022
1 parent
c1a8f7d
commit ab26e85
Showing
5 changed files
with
113 additions
and
12 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ def add(x, y=0): | |
result = reduce(add, result) | ||
|
||
blazer.print(result) | ||
|
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,27 @@ | ||
import blazer | ||
from blazer.hpc.mpi import mapreduce, reduce, rank | ||
|
||
|
||
def sqr(x): | ||
return x * x | ||
|
||
|
||
def add(values): | ||
if values and len(values): | ||
return sum(values) | ||
else: | ||
return 0 | ||
|
||
|
||
with blazer.begin(): | ||
if blazer.ROOT: | ||
data = list(range(0, 100)) | ||
print("DATA: ",data) | ||
print("EXPECTING: ",sum(data)) | ||
else: | ||
data = None | ||
|
||
result = mapreduce(add, add, data) | ||
|
||
blazer.print("RESULT:", result) | ||
|
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,44 @@ | ||
import blazer | ||
from blazer.hpc.mpi import parallel, pipeline, partial as p, scatter, where, select, filter, rank, size | ||
|
||
|
||
def calc_some(value, *args): | ||
""" Do some calculations """ | ||
result = {'some': value} | ||
return result | ||
|
||
|
||
def calc_stuff(value, *args): | ||
""" Do some calculations """ | ||
result = {'this': value} | ||
return result | ||
|
||
|
||
def add_date(result): | ||
from datetime import datetime | ||
if type(result) is dict: | ||
result['date'] = str(datetime.now()) | ||
return result | ||
|
||
|
||
def calc_more_stuff(result): | ||
""" Do some more calculations """ | ||
if type(result) is list: | ||
result += [{'more': 'stuff'}] | ||
elif type(result) is dict: | ||
result['more'] = 'stuff' | ||
return result | ||
|
||
|
||
INPUT_DATA = 'that' | ||
|
||
with blazer.begin(): | ||
|
||
def get_data(): | ||
""" Data generator """ | ||
for i in range(0, (size * 2)): | ||
yield i | ||
|
||
|
||
result = scatter(get_data(), calc_some) | ||
blazer.print("SCATTER:", result) |
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