public byte[] Call(byte[] memento) { _groupCommClient.Initialize(); Stopwatch broadcastTime = new Stopwatch(); Stopwatch reduceTime = new Stopwatch(); for (int i = 0; i < _numIterations; i++) { broadcastTime.Start(); // Receive n from Master Task int n = _broadcastReceiver.Receive(); broadcastTime.Stop(); Logger.Log(Level.Info, "Calculating TriangleNumber({0}) on slave task...", n); // Calculate the nth Triangle number and send it back to driver int triangleNum = TriangleNumber(n); Logger.Log(Level.Info, "Sending sum: {0} on iteration {1}.", triangleNum, i); reduceTime.Start(); _triangleNumberSender.Send(triangleNum); reduceTime.Stop(); if (i >= 1) { var msg = string.Format("Average time (milliseconds) taken for broadcast: {0} and reduce: {1}", broadcastTime.ElapsedMilliseconds / ((double)i), reduceTime.ElapsedMilliseconds / ((double)i)); Logger.Log(Level.Info, msg); } } return(null); }
/// <summary> /// Handle the exceptions in the Call() method /// Default to IMRUSystemException to make it recoverable /// </summary> public byte[] Call(byte[] memento) { Logger.Log(Level.Info, "Entering {0} Call().", TaskHostName); try { _groupCommunicationsClient.Initialize(_cancellationSource); return(TaskBody(memento)); } catch (Exception e) { if (e is IMRUTaskAppException) { throw; } if (IsCommunicationException(e)) { HandleCommunicationException(e); } else { HandleSystemException(e); } } finally { _taskCloseCoordinator.SignalTaskStopped(); } Logger.Log(Level.Info, "{0} returned with cancellation token:{1}.", TaskHostName, _cancellationSource.IsCancellationRequested); return(null); }
public byte[] Call(byte[] memento) { _groupCommClient.Initialize(); int[] intArr = new int[_arraySize]; for (int j = 0; j < _arraySize; j++) { intArr[j] = j; } Stopwatch broadcastTime = new Stopwatch(); Stopwatch reduceTime = new Stopwatch(); for (int i = 1; i <= _numIters; i++) { intArr[0] = i; if (i == 2) { broadcastTime.Reset(); reduceTime.Reset(); } broadcastTime.Start(); _broadcastSender.Send(intArr); broadcastTime.Stop(); reduceTime.Start(); int[] sum = _sumReducer.Reduce(); reduceTime.Stop(); Logger.Log(Level.Info, "Received sum: {0} on iteration: {1} with array length: {2}", sum[0], i, sum.Length); int expected = TriangleNumber(i) * _numReduceSenders; if (sum[0] != TriangleNumber(i) * _numReduceSenders) { throw new Exception("Expected " + expected + " but got " + sum[0]); } if (i >= 2) { var msg = string.Format("Average time (milliseconds) taken for broadcast: {0} and reduce: {1}", broadcastTime.ElapsedMilliseconds / ((double)(i - 1)), reduceTime.ElapsedMilliseconds / ((double)(i - 1))); Logger.Log(Level.Info, msg); } } return(null); }
public byte[] Call(byte[] memento) { _groupCommClient.Initialize(); List <int> data = Enumerable.Range(1, 100).ToList(); _scatterSender.Send(data); int sum = _sumReducer.Reduce(); Logger.Log(Level.Info, "Received sum: {0}", sum); return(null); }
public byte[] Call(byte[] memento) { _groupCommClient.Initialize(); List <int> data = _scatterReceiver.Receive(); Logger.Log(Level.Info, "Received data: {0}", string.Join(" ", data)); int sum = data.Sum(); Logger.Log(Level.Info, "Sending back sum: {0}", sum); _sumSender.Send(sum); return(null); }
public byte[] Call(byte[] memento) { _groupCommClient.Initialize(); Stopwatch broadcastTime = new Stopwatch(); Stopwatch reduceTime = new Stopwatch(); for (int i = 1; i <= _numIters; i++) { if (i == 2) { broadcastTime.Reset(); reduceTime.Reset(); } broadcastTime.Start(); // Each slave task calculates the nth triangle number _broadcastSender.Send(i); broadcastTime.Stop(); reduceTime.Start(); // Sum up all of the calculated triangle numbers int sum = _sumReducer.Reduce(); reduceTime.Stop(); Logger.Log(Level.Info, "Received sum: {0} on iteration: {1}", sum, i); int expected = TriangleNumber(i) * _numReduceSenders; if (sum != TriangleNumber(i) * _numReduceSenders) { throw new Exception("Expected " + expected + " but got " + sum); } if (i >= 2) { var msg = string.Format("Average time (milliseconds) taken for broadcast: {0} and reduce: {1}", broadcastTime.ElapsedMilliseconds / ((double)(i - 1)), reduceTime.ElapsedMilliseconds / ((double)(i - 1))); Logger.Log(Level.Info, msg); } } return(null); }
public byte[] Call(byte[] memento) { _groupCommClient.Initialize(); while (true) { if (_controlBroadcastReceiver.Receive() == ControlMessage.STOP) { break; } Centroids centroids = _dataBroadcastReceiver.Receive(); // we compute the loss here before data is relabled, this does not reflect the latest clustering result at the end of current iteration, // but it will save another round of group communications in each iteration Logger.Log(Level.Info, "Received centroids from master: " + centroids); _dataPartition.LabelData(centroids); ProcessedResults partialMeans = new ProcessedResults(ComputePartialMeans(), ComputeLossFunction(centroids, _dataPartition.DataVectors)); Logger.Log(Level.Info, "Sending partial means: " + partialMeans); _partialMeansSender.Send(partialMeans); } return(null); }