Commit 721dfd48 authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

wip

parent 196e9114
Pipeline #2845 passed with stage
in 0 seconds
//
// clusterpi.js
// Neil Gershenfeld 11/23/18
// Neil Gershenfeld 12/8/18
// pi calculation benchmark
// pi = 3.14159265358979323846
//
const cluster = require('cluster')
const points = 1e8
if (cluster.isMaster)
master()
else
child()
function master() {
var processes = require('os').cpus().length
var tstart = Date.now()/1000
for (var i = 0; i < processes; i++)
cluster.fork()
var index = 0
var processes = parseInt(process.argv[2])
var points = 1e9
var pi = 0
var results = 0
for (const id in cluster.workers) {
var worker = cluster.workers[id]
var tstart = Date.now()/1000
for (var i = 0; i < processes; i++) {
var worker = cluster.fork({index:i,points:points})
worker.on('message',(result) => {
pi += result
results += 1
......@@ -33,17 +30,11 @@ function master() {
process.exit()
}
})
function send(index) {
return function() {
worker.send(index)
}
}
worker.on('online',send(index))
index += 1
}
}
function child() {
process.on('message',(index) => {
var index = parseInt(process.env.index)
var points = parseInt(process.env.points)
var a = 0.5
var b = 0.75
var c = 0.25
......@@ -53,5 +44,4 @@ function child() {
for (var i = start; i <= end; ++i)
sum += a/((i-b)*(i-c))
process.send(sum)
})
}
......@@ -11,8 +11,8 @@ var pi = 0
var results = 0
var tstart = Date.now()/1000
for (let i = 0; i < processes; ++i) {
id = fork('forkspi.js',[i,points])
id.on('message',(result) => {
const child = fork('forkspi.js',[i,points])
child.on('message',(result) => {
pi += result
results += 1
if (results == processes) {
......
//
// forkspi.js
// Neil Gershenfeld 11/23/18
// Neil Gershenfeld 12/8/18
// pi calculation benchmark
// pi = 3.14159265358979323846
//
......
......@@ -4,7 +4,7 @@
// pi calculation benchmark
// pi = 3.14159265358979323846
//
var points = 1e8
var points = 1e9
var a = 0.5
var b = 0.75
var c = 0.25
......
......@@ -6,10 +6,12 @@
|71.46|[pi.html](https://pub.pages.cba.mit.edu/pi/JavaScript/pi.html)|JavaScript, 56 workers|Intel 2x E5-2680|Nov 19, 2018|
|46.96|[mpipi.c](MPI/mpipi.c)|C, MPI<br>mpicc mpipi.c -o mpipi -O3 -ffast-math <br> mpirun -np 6 mpipi|Intel i7-8700T|Nov 17, 2018|
|16.16|[pi.html](https://pub.pages.cba.mit.edu/pi/JavaScript/pi.html)|JavaScript, 6 workers|Intel i7-8700T|Nov 17, 2018|
|14.34|[clusterpi.js](Node/clusterpi.js)|Node, 6 workers|Intel i7-8700T|Dec 8, 2018|
|9.371|[pi.c](C/pi.c)|C<br>gcc pi.c -o pi -lm -O3 -ffast-math|Intel i7-8700T|Nov 17, 2018|
|3.817|[pi.js](Node/pi.js)|Node|Intel 2x E5-2680|Nov 24, 2018|
|3.734|[pi.html](https://pub.pages.cba.mit.edu/pi/JavaScript/pi.html)|JavaScript, 1 worker|Intel i7-8700T|Nov 17, 2018|
|3.472|[pi.html](https://pub.pages.cba.mit.edu/pi/JavaScript/pi.html)|JavaScript, 1 worker|Intel 2x E5-2680|Nov 19, 2018|
|3.817|[pi.js](Node/pi.js)|Node|Intel 2x E5-2680|Nov 24, 2018|
|3.184|[clusterpi.js](Node/clusterpi.js)|Node, 1 worker|Intel i7-8700T|Dec 8, 2018|
|0.573|[pi.c](C/pi.c)|C<br>gcc pi.c -o pi -lm|Intel i7-8700T|Nov 17, 2018|
|0.470|[numpi.py](Python/numpi.py)|Python, NumPy|Intel i7-8700T|Nov 17, 2018|
|0.029|[pi.py](Python/pi.py)|Python|Intel i7-8700T|Nov 17, 2018|
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment