This repository has been archived by the owner on Aug 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
198 additions
and
13 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
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,3 @@ | ||
map.js | ||
reduce.js | ||
*.wasm |
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,12 @@ | ||
import {AbstractInputData} from '../../'; | ||
|
||
export default | ||
class MyInputData extends AbstractInputData { | ||
|
||
constructor() { | ||
super(); | ||
this.addInputData('https://raw.githubusercontent.com/h-matsuo/madoop/master/README.md'); | ||
this.addInputData('https://raw.githubusercontent.com/h-matsuo/madoop/master/LICENSE'); | ||
} | ||
|
||
} |
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,20 @@ | ||
import {AbstractShuffler} from '../../'; | ||
|
||
export default | ||
class MyShuffler extends AbstractShuffler { | ||
|
||
setUpReducerInputData( | ||
mapperResult: Map<any, any[]> | ||
): Map<any, any[]>[] { | ||
|
||
const reduceInputData = []; | ||
const data = new Map<any, any[]>(); | ||
mapperResult.forEach((values, key) => { | ||
data.set(key, values); | ||
}); | ||
reduceInputData.push(data); | ||
return reduceInputData; | ||
|
||
} | ||
|
||
} |
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,38 @@ | ||
import {Job, WasmMapper, WasmReducer, WasmWebServer} from '../../'; | ||
import MyInputData from './MyInputData'; | ||
import MyShuffler from './MyShuffler'; | ||
|
||
import * as fs from 'fs'; | ||
|
||
const job = new Job('preprocess'); | ||
const inputData = new MyInputData(); | ||
const mapper = new WasmMapper(); | ||
const reducer = new WasmReducer(); | ||
const shuffler = new MyShuffler(); | ||
const server = new WasmWebServer(); | ||
|
||
const wasmJsMap = fs.readFileSync('./map.js', 'utf8'); | ||
const wasmBinaryMap = fs.readFileSync('./map.wasm'); | ||
const wasmPreprocessJsMap = fs.readFileSync('./wasm_map_preprocess.js', 'utf8'); | ||
mapper.setWasmJs(wasmJsMap); | ||
mapper.setWasmBinary(wasmBinaryMap); | ||
mapper.setWasmPreprocessJs(wasmPreprocessJsMap); | ||
|
||
const wasmJsReducer = fs.readFileSync('./reduce.js', 'utf8'); | ||
const wasmBinaryReducer = fs.readFileSync('./reduce.wasm'); | ||
const wasmPreprocessJsReducer = fs.readFileSync('./wasm_reduce_preprocess.js', 'utf8'); | ||
reducer.setWasmJs(wasmJsReducer); | ||
reducer.setWasmBinary(wasmBinaryReducer); | ||
reducer.setWasmPreprocessJs(wasmPreprocessJsReducer); | ||
|
||
job.setInputData(inputData); | ||
job.setMapper(mapper); | ||
job.setReducer(reducer); | ||
job.setShuffler(shuffler); | ||
job.setCallbackWhenCompleted(result => { | ||
console.log(result); | ||
process.exit(0); | ||
}); | ||
server.setJob(job); | ||
server.setRoot('/madoop/wasm'); | ||
server.run(); |
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 @@ | ||
#!/usr/bin/env bash | ||
|
||
EMSCRIPTEN_IMAGE_NAME="trzeci/emscripten-slim" | ||
EMSCRIPTEN_IMAGE_TAG="sdk-tag-1.38.8-64bit" | ||
|
||
SCRIPT_DIR="$(cd $(dirname "${BASH_SOURCE:-$0}"); pwd)" | ||
|
||
run_emscripten () { | ||
docker run --rm -t \ | ||
-v "${SCRIPT_DIR}:/src" \ | ||
"${EMSCRIPTEN_IMAGE_NAME}:${EMSCRIPTEN_IMAGE_TAG}" "$@" | ||
} | ||
|
||
compile() { | ||
run_emscripten emcc "${1}.cpp" \ | ||
-std=c++11 \ | ||
-s WASM=1 \ | ||
-s MODULARIZE=1 \ | ||
-s ALLOW_MEMORY_GROWTH=1 \ | ||
-s "EXPORTED_FUNCTIONS=['_${1}']" \ | ||
-s "EXTRA_EXPORTED_RUNTIME_METHODS=['cwrap', 'lengthBytesUTF8', 'stringToUTF8']" \ | ||
--js-library lib_emit_func.js \ | ||
-o "${1}.js" | ||
} | ||
|
||
compile map | ||
compile reduce |
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 @@ | ||
mergeInto(LibraryManager.library, { | ||
emit_func: function (key, value) { | ||
execEmit(Pointer_stringify(key), Pointer_stringify(value)); | ||
} | ||
}); |
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,14 @@ | ||
#include <iostream> | ||
|
||
extern "C" { // REQUIRED to prevent C++ name mangling | ||
|
||
extern void emit_func(const char*, const char*); // REQUIRED to emit key-value pairs | ||
|
||
void map(const char* data) | ||
{ | ||
std::cout << "received data (preprocessed by wasm_map_preprocess.js):" | ||
<< std::endl << data << std::endl; | ||
emit_func("this-key-will-be-overwritten-by-wasm_reduce_preprocess.js", data); | ||
} | ||
|
||
} |
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,10 @@ | ||
extern "C" { // REQUIRED to prevent C++ name mangling | ||
|
||
extern void emit_func(const char*, const char*); // REQUIRED to emit key-value pairs | ||
|
||
void reduce(const char* key, const char* values_str) | ||
{ | ||
emit_func(key, values_str); | ||
} | ||
|
||
} |
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,4 @@ | ||
madoop.runtime.wasmMapPreprocess = async url => { | ||
const text = await fetch(url).then(res => res.text()); | ||
return text; | ||
}; |
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,3 @@ | ||
madoop.runtime.wasmReducePreprocess = async ({key: key, value: value}) => { | ||
return {key: 'this-key-was-overwritten', value: value}; | ||
}; |
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
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