public async Task RunAsync() { // Do warmup rounds for (var i = 0L; i < WARMUP; i++) { await m_channel.ReadAsync(); } Console.WriteLine("Warmup complete, measuring"); for (int r = 0; r < REPEATS; r++) { // Measure the run var start = DateTime.Now; for (var i = 0L; i < ROUNDS; i++) { await m_channel.ReadAsync(); } var finish = DateTime.Now; // Report Console.WriteLine("Time per iteration: {0} microseconds", ((finish - start).TotalMilliseconds * 1000) / ROUNDS); Console.WriteLine("Time per communication: {0} microseconds", ((finish - start).TotalMilliseconds * 1000) / ROUNDS / 4); } // Cleanup m_channel.Retire(); }
public async override Task RunAsync() { try { while (true) { await m_output.WriteAsync(await m_input.ReadAsync() + 1); } } catch (RetiredException) { m_input.Retire(); m_output.Retire(); } }
/// <summary> /// Runs the identity process, which simply forwards a value. /// </summary> /// <param name="chan_read">The channel to read from</param> /// <param name="chan_write">The channel to write to</param> private static async void RunIdentity(IReadChannel <T> chan_read, IWriteChannel <T> chan_write) { try { while (true) { await chan_write.WriteAsync(await chan_read.ReadAsync()); } } catch (RetiredException) { chan_read.Retire(); chan_write.Retire(); } }
public async override Task RunAsync() { try { while(m_repeat-- > 0) await m_output.WriteAsync(m_value); while (true) await m_output.WriteAsync(await m_input.ReadAsync()); } catch (RetiredException) { m_input.Retire(); m_output.Retire(); } }
/// <summary> /// A process that reads numbers and discards those that are /// divisible by a certain number and forwards the rest /// </summary> /// <returns>The awaitable task that represents the process</returns> /// <param name="number">The number used to test and filter divisible numbers with.</param> /// <param name="input">The channel where data is read from.</param> /// <param name="output">The channel where non-multiple values are written to.</param> private static async Task RunNoMultiplesAsync(long number, IReadChannel <long> input, IWriteChannel <long> output) { try { while (true) { var v = await input.ReadAsync(); if (v % number != 0) { await output.WriteAsync(v); } } } catch (RetiredException) { input.Retire(); output.Retire(); } }
/// <summary> /// Runs the process. /// </summary> /// <returns>An awaitable task.</returns> public async override Task RunAsync() { try { while (true) { var r = await m_input.ReadAsync(); await Task.WhenAll( m_outputA.WriteAsync(r), m_outputB.WriteAsync(r) ); } } catch (RetiredException) { m_input.Retire(); m_outputA.Retire(); m_outputB.Retire(); } }
/// <summary> /// Runs the delta process, which copies the value it reads onto two different channels /// </summary> /// <param name="chan_read">The channel to read from</param> /// <param name="chan_a">The channel to write to</param> /// <param name="chan_b">The channel to write to</param> private static async void RunDelta(IReadChannel <T> chan_read, IWriteChannel <T> chan_a, IWriteChannel <T> chan_b) { try { while (true) { var value = await chan_read.ReadAsync(); await Task.WhenAll( chan_a.WriteAsync(value), chan_b.WriteAsync(value) ); } } catch (RetiredException) { chan_read.Retire(); chan_a.Retire(); chan_b.Retire(); } }
/// <summary> /// Runs the delta process, which copies the value it reads onto two different channels /// </summary> /// <param name="chan_read">The channel to read from</param> /// <param name="chan_a">The channel to write to</param> /// <param name="chan_b">The channel to write to</param> private static async void RunDeltaAlt(IReadChannel <T> chan_read, IWriteChannel <T> chan_a, IWriteChannel <T> chan_b) { try { while (true) { var value = await chan_read.ReadAsync(); var offer = new SingleOffer <T>(); await Task.WhenAll( chan_a.WriteAsync(value), chan_b.WriteAsync(value, CoCoL.Timeout.Infinite, offer) ); } } catch (RetiredException) { chan_read.Retire(); chan_a.Retire(); chan_b.Retire(); } }
/// <summary> /// A process that spawns a new set of processes /// when a number is received. /// By inserting a NoMultiples into the chain, /// it is guaranteed that no numbers that are divisible /// with any number in the chain can be retrieved by the /// Sieve. /// </summary> /// <returns>The awaitable task that represents the process</returns> /// <param name="input">The channel to read numbers from</param> /// <param name="output">The channel to write numbers to</param> private static async Task RunSieveAsync(IReadChannel <long> input, IWriteChannel <long> output) { var chan = ChannelManager.CreateChannel <long>(); try { var n = await input.ReadAsync(); await output.WriteAsync(n); await Task.WhenAll( RunNoMultiplesAsync(n, input, chan), RunSieveAsync(chan, output) ); } catch (RetiredException) { chan.Retire(); input.Retire(); output.Retire(); } }
/// <summary> /// Runs the tick collector process which measures the network performance /// </summary> /// <returns>The awaitable tick collector task.</returns> /// <param name="chan">The tick channel.</param> /// <param name="stop">The channel used to shut down the network.</param> private static async Task RunTickCollectorAsync(IReadChannel <T> chan, IChannel <T> stop, bool stop_after_tickcount) { var tickcount = 0; var rounds = 0; //Initialize await chan.ReadAsync(); var a_second = TimeSpan.FromSeconds(1).Ticks; //Warm up Console.WriteLine("Warming up ..."); DateTime m_last = DateTime.Now; while (await chan.ReadAsync() != 0) { if ((DateTime.Now - m_last).Ticks > a_second) { break; } } //Measuring Console.WriteLine("Measuring!"); var measure_span = TimeSpan.FromSeconds(5).Ticks; m_last = DateTime.Now; try { while (await chan.ReadAsync() != 0) { tickcount++; bool round_complete; if (stop_after_tickcount) { round_complete = tickcount >= Config.Ticks; } else { round_complete = (DateTime.Now - m_last).Ticks >= measure_span; } if (round_complete) { var duration = DateTime.Now - m_last; Console.WriteLine("Got {0} ticks in {1} seconds, speed is {2} rounds/s ({3} msec/comm)", tickcount, duration, tickcount / duration.TotalSeconds, duration.TotalMilliseconds / ((tickcount) * Config.Processes)); Console.WriteLine("Time per iteration: {0} microseconds", (duration.TotalMilliseconds * 1000) / tickcount); Console.WriteLine("Time per communication: {0} microseconds", (duration.TotalMilliseconds * 1000) / tickcount / 4); tickcount = 0; m_last = DateTime.Now; // For shutdown, we retire the initial channel if (++rounds >= Config.MeasureCount) { stop.Retire(); } } } } catch (RetiredException) { chan.Retire(); } }