コード例 #1
0
        static void Main(string[] args)
        {
            using (new MPI.Environment(ref args))
            {
                DSM dsm = new DSM();

                if (Communicator.world.Rank == 0)
                {
                    Thread thread = new Thread(listenerThread);
                    thread.Start(dsm);

                    bool exit = false;

                    dsm.subscribeTo("a");
                    dsm.subscribeTo("b");
                    dsm.subscribeTo("c");

                    while (!exit)
                    {
                        Console.WriteLine("1. Set var");
                        Console.WriteLine("2. Change var");
                        Console.WriteLine("0. Exit");

                        int answer;
                        int.TryParse(Console.ReadLine(), out answer);

                        if (answer == 0)
                        {
                            dsm.close();
                            exit = true;
                        }
                        else if (answer == 1)
                        {
                            Console.WriteLine("var (a, b, c) = ");
                            string var = Console.ReadLine();

                            Console.WriteLine("val (int) = ");
                            int val;
                            int.TryParse(Console.ReadLine(), out val);

                            dsm.updateVar(var, val);
                            writeVars(dsm);
                        }
                        else if (answer == 2)
                        {
                            Console.WriteLine("var to check (a, b, c) = ");
                            string var = Console.ReadLine();

                            Console.WriteLine("val to check (int) = ");
                            int val;
                            int.TryParse(Console.ReadLine(), out val);

                            Console.WriteLine("val to check (int) = ");
                            int newVal;
                            int.TryParse(Console.ReadLine(), out newVal);

                            dsm.checkAndReplace(var, val, newVal);
                        }
                    }
                }
                else if (Communicator.world.Rank == 1)
                {
                    Thread thread = new Thread(listenerThread);
                    thread.Start(dsm);

                    dsm.subscribeTo("a");

                    thread.Join();
                }
                else if (Communicator.world.Rank == 2)
                {
                    Thread thread = new Thread(listenerThread);
                    thread.Start(dsm);

                    dsm.subscribeTo("b");

                    thread.Join();
                }
            }
        }