Created
August 27, 2013 05:05
-
-
Save amad/6349793 to your computer and use it in GitHub Desktop.
Grid computing matrix process
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
var socket = io.connect('http://grid.moeinhm.ir:3000'); | |
var GridTask = new Worker('matrix.js'); | |
GridTask.postMessage('doIt'); | |
GridTask.onmessage = function(result){ | |
socket.emit('result',result); | |
GridTask.postMessage('doIt'); | |
}; | |
GridTask.onmessage(result); | |
socket.on('unProcessedData',function(data){ | |
GridTask.postMessage(data[0]); | |
console.log("data:") | |
console.log(data[0]); | |
}); | |
GridTask.onmessage = function(result){ | |
socket.emit('result',result); | |
console.log("result:") | |
console.log(result); | |
}; | |
socket.emit('ready',{}); |
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
var multipliction = function(matrixA,matrixB){ | |
var result = []; | |
for (var counter=0;counter < 9999;counter++){ | |
result = new Array(); | |
for (var i = 0;i < matrixA.length;i++){ | |
result.push(new Array()); | |
for (var j = 0;j < matrixB.length;j++) | |
result[i].push(0); | |
} | |
for (var i = 0;i < matrixA.length;i++) | |
for (var j = 0;j < matrixA[i].length ;j++) | |
for(var k = 0;k < matrixB[j].length;k++) | |
result[i][j] += matrixA[i][k] * matrixB[k][j]; | |
} | |
return result; | |
}; | |
var onmessage = function(message){ | |
var result = { | |
'_id':message.data._id, | |
'result':multipliction(message.data.matrixA,message.data.matrixB) | |
}; | |
postMessage(result); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment