Пример #1
0
        /// <summary>
        /// The entry point of the program, where the program control starts and ends.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            if (!Config.Parse(args))
            {
                return;
            }

            Console.WriteLine("Config is: {0}", Config.AsString());

            var anynetwork = Config.AllChannelsNetworked || Config.TickChannelNetworked;

            var servertoken = new CancellationTokenSource();
            var server      = (anynetwork && Config.ChannelServerSelfHost) ? NetworkChannelServer.HostServer(servertoken.Token, Config.ChannelServerHostname, Config.ChannelServerPort) : null;

            if (anynetwork && !Config.ChannelServerSelfHost)
            {
                NetworkConfig.Configure(Config.ChannelServerHostname, Config.ChannelServerPort, true);
            }

            using (anynetwork ? new NetworkChannelScope(n => {
                if (Config.TickChannelNetworked)
                {
                    return(string.Equals(n, "tick"));
                }
                else if (Config.AllChannelsNetworked)
                {
                    return(true);
                }

                return(false);
            }) : null)
            {
                var chan_in   = ChannelManager.CreateChannel <T>();
                var chan_tick = ChannelManager.CreateChannel <T>("tick");
                var chan_out  = ChannelManager.CreateChannel <T>();

                // Start the delta process
                if (Config.UseAltingForDeltaProcess)
                {
                    RunDeltaAlt(AsBufferedRead(chan_in), AsBufferedWrite(chan_out), AsBufferedWrite(chan_tick));
                }
                else
                {
                    RunDelta(AsBufferedRead(chan_in), AsBufferedWrite(chan_out), AsBufferedWrite(chan_tick));
                }

                IChannel <T> chan_new = null;

                // Spin up the forwarders
                for (var i = 0; i < Config.Processes - 2; i++)
                {
                    //Console.WriteLine("Starting process {0}", i);
                    chan_new = ChannelManager.CreateChannel <T>();
                    RunIdentity(AsBufferedRead(chan_out), AsBufferedWrite(chan_new));
                    chan_out = chan_new;
                }

                // Close the ring
                RunIdentity(AsBufferedRead(chan_out), AsBufferedWrite(chan_in));

                // Start the tick collector
                var t = RunTickCollectorAsync(AsBufferedRead(chan_tick), chan_in, Config.StopWithTicks);

                // Inject a value into the ring
                chan_in.WriteNoWait(1);

                Console.WriteLine("Running, press CTRL+C to stop");

                // Wait for the tick collector to finish measuring
                t.WaitForTaskOrThrow();

                // Shut down the server if it is running
                if (server != null)
                {
                    servertoken.Cancel();
                    server.WaitForTaskOrThrow();
                }
            }
        }
Пример #2
0
        public static void Main(string[] args)
        {
            if (!Config.Parse(args))
            {
                return;
            }

            Console.WriteLine("Config is: {0}", Config.AsString());

            var servertoken = new CancellationTokenSource();
            var server      = (Config.NetworkedChannels && Config.ChannelServerSelfHost) ? NetworkChannelServer.HostServer(servertoken.Token, Config.ChannelServerHostname, Config.ChannelServerPort) : null;

            if (Config.NetworkedChannels && !Config.ChannelServerSelfHost)
            {
                NetworkConfig.Configure(Config.ChannelServerHostname, Config.ChannelServerPort, true);
            }

            using (Config.NetworkedChannels ? new NetworkChannelScope(redirectunnamed: true) : null)
            {
                Console.WriteLine("Running with {0} channels and {1} writers, a total of {2} communications pr. round", Config.Channels, Config.Writers, Config.Channels * Config.Writers);

                var allchannels = (from n in Enumerable.Range(0, Config.Channels)
                                   select ChannelManager.CreateChannel <long>()).ToArray();

                var tasks = new List <Task>();
                for (var i = 0; i < allchannels.Length; i++)
                {
                    for (var j = 0; j < Config.Writers; j++)
                    {
                        tasks.Add(RunWriterAsync(i, AsBufferedWrite(allchannels[i])));
                    }
                }

                tasks.Add(new Reader(allchannels.Select(x => AsBufferedRead(x)).ToArray(), Config.Writers).RunAsync());

                Task.WhenAll(tasks).WaitForTaskOrThrow();

                Console.WriteLine("All tasks completed");
            }

            servertoken.Cancel();
            if (server != null)
            {
                server.WaitForTaskOrThrow();
            }

            if (WriterCount != 0)
            {
                Console.WriteLine("Terminating, with {0} writers active", WriterCount);
            }
        }
Пример #3
0
        public static void Main(string[] _args)
        {
            var args = new List <string>(_args);

            // Send jobs into the network
            if (!Config.Parse(args))
            {
                return;
            }

            Console.WriteLine("Config is: {0}", Config.AsString());

            var servertoken = new CancellationTokenSource();
            var server      = (Config.NetworkedChannels && Config.ChannelServerSelfHost) ? NetworkChannelServer.HostServer(servertoken.Token, Config.ChannelServerHostname, Config.ChannelServerPort) : null;

            if (Config.NetworkedChannels && !Config.ChannelServerSelfHost)
            {
                NetworkConfig.Configure(Config.ChannelServerHostname, Config.ChannelServerPort, true);
            }

            using (Config.NetworkedChannels ? new NetworkChannelScope(redirectunnamed: true) : null)
                foreach (var job in Enumerable.Range(0, Config.Repeats).Select(x => new Render(Config.Width, Config.Height, Config.Iterations)))
                {
                    job.Run();
                }

            servertoken.Cancel();
            if (server != null)
            {
                server.WaitForTaskOrThrow();
            }
        }