Exemple #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("[enter] to start grid application ...");
            Console.ReadLine();

            // create standard grid connection
            GConnection gc = new GConnection("localhost", 9000, "user", "user");

            // create multi-use grid application
            ga = new GApplication(true);
            ga.ApplicationName = "Tutorial OTF - Alchemi sample";

            // use standard grid connection
            ga.Connection = gc;

            // add GridThread module (this executable) as a dependency
            ga.Manifest.Add(new ModuleDependency(typeof(MultiplierThread).Module));

            // set the thread finish callback method
            ga.ThreadFinish += new GThreadFinish(ThreadFinished);

            // start application
            ga.Start();

            int    i     = -1;
            string input = "";

            while (input != "x")
            {
                i++;
                // create thread
                MultiplierThread thread = new MultiplierThread(i, i + 1);

                // add thread to application
                ga.StartThread(thread);

                Console.WriteLine("[enter] to start a new thread, [x] + [enter] to stop");
                input = Console.ReadLine();
            }

            ga.Stop();

            ApplicationStopped();
            Console.ReadLine();
        }
        private static void Init()
        {
            try
            {
                // get settings from user
                GConnection gc = GConnection.FromConsole("localhost", "9000", "user", "user");
                StartTime      = DateTime.Now;
                App.Connection = gc;

                // grid thread needs to
                App.Manifest.Add(new ModuleDependency(typeof(PrimeNumberChecker).Module));

                // subscribe to ThreadFinish event
                App.ThreadFinish      += new GThreadFinish(App_ThreadFinish);
                App.ApplicationFinish += new GApplicationFinish(App_ApplicationFinish);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                logger.Error("ERROR: ", ex);
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press [enter] to start ...");
            Console.ReadLine();

            try
            {
                ga = new GApplication(GConnection.FromConsole("localhost", "9000", "user", "user"));
                ga.ApplicationName = "Grid Reverser - Alchemi sample";

                ga.ThreadFinish      += new GThreadFinish(JobFinished);
                ga.ApplicationFinish += new GApplicationFinish(ApplicationFinished);

                ga.Manifest.Add(new EmbeddedFileDependency("Reverse.exe", @"..\..\..\Reverse\bin\Debug\Reverse.exe"));

                for (int jobNum = 0; jobNum < 2; jobNum++)
                {
                    GJob   job            = new GJob();
                    string inputFileName  = string.Format("input{0}.txt", jobNum);
                    string outputFileName = string.Format("output{0}.txt", jobNum);

                    job.InputFiles.Add(new EmbeddedFileDependency(inputFileName, @"..\..\" + inputFileName));
                    job.RunCommand = string.Format("Reverse {0} > {1}", inputFileName, outputFileName);
                    job.OutputFiles.Add(new EmbeddedFileDependency(outputFileName));

                    ga.Threads.Add(job);
                }

                ga.Start();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.GetType() + " : " + e.Message);
                Console.ReadLine();
                return;
            }
            Console.WriteLine("Started .. Waiting for jobs to finish ..\n");
            Console.ReadLine();
        }
Exemple #4
0
        static void Main()
        {
            Console.WriteLine("[Pi Calculator Grid Application]\n--------------------------------\n");

            Console.WriteLine("Press <enter> to start ...");
            Console.ReadLine();

            Logger.LogHandler += new LogEventHandler(LogHandler);

            try
            {
                // get the number of digits from the user
                bool numberOfDigitsEntered = false;

                while (!numberOfDigitsEntered)
                {
                    try
                    {
                        NumberOfDigits = Int32.Parse(Utils.ValueFromConsole("Digits to calculate", "100"));

                        if (NumberOfDigits > 0)
                        {
                            numberOfDigitsEntered = true;
                        }
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Invalid numeric value.");
                        numberOfDigitsEntered = false;
                    }
                }

                // get settings from user
                GConnection gc = GConnection.FromConsole("localhost", "9000", "user", "user");

                StartTiming();

                // create a new grid application
                App = new GApplication(gc);
                App.ApplicationName = "PI Calculator - Alchemi sample";

                // add the module containing PiCalculatorThread to the application manifest
                App.Manifest.Add(new ModuleDependency(typeof(PiCalculatorThread).Module));

                NumThreads = (Int32)Math.Floor((double)NumberOfDigits / DigitsPerThread);
                if (DigitsPerThread * NumThreads < NumberOfDigits)
                {
                    NumThreads++;
                }

                // create and add the required number of grid threads
                for (int i = 0; i < NumThreads; i++)
                {
                    int StartDigitNum = 1 + (i * DigitsPerThread);

                    /// the number of digits for each thread
                    /// Each thread will get DigitsPerThread digits except the last one
                    /// which might get less
                    int DigitsForThisThread = Math.Min(DigitsPerThread, NumberOfDigits - i * DigitsPerThread);

                    Console.WriteLine(
                        "starting a thread to calculate the digits of pi from {0} to {1}",
                        StartDigitNum,
                        StartDigitNum + DigitsForThisThread - 1);

                    PiCalculatorThread thread = new PiCalculatorThread(
                        StartDigitNum,
                        DigitsForThisThread
                        );

                    App.Threads.Add(thread);
                }

                // subcribe to events
                App.ThreadFinish      += new GThreadFinish(ThreadFinished);
                App.ApplicationFinish += new GApplicationFinish(ApplicationFinished);

                // start the grid application
                App.Start();

                logger.Debug("PiCalc started.");
            }
            catch (Exception e)
            {
                Console.WriteLine("ERROR: {0}", e.ToString());
            }

            Console.ReadLine();
        }
Exemple #5
0
 /// <summary>
 /// Creates a new instance of the GConnection class
 /// </summary>
 /// <param name="connection"></param>
 public GNode(GConnection connection)
 {
     Connection = connection;
     Init();
 }
Exemple #6
0
 /// <summary>
 /// Creates a new instance of the GConnection class
 /// </summary>
 /// <param name="connection">The connection.</param>
 protected GNode(GConnection connection)
 {
     Connection = connection;
     Init();
 }
Exemple #7
0
 public ConsoleNode(GConnection gc)
     : base(gc)
 {
 }
Exemple #8
0
        void Run()
        {
            // All grid applications must have a GApplication instance.  The GConnection information
            // specifies the Manager's host name, the port to connect on, and the username and password
            // to use.  A GApplication is created with this connection information.
            GConnection  gridConnection  = new GConnection("localhost", 9000, "user", "user");
            GApplication gridApplication = new GApplication(gridConnection);

            while (!File.Exists(this._inputFileName))
            {
                if (this._inputFileName != null)
                {
                    Console.WriteLine("\nFile does not exist.  Please try again.\n");
                }
                Console.WriteLine("Enter the input file name: ");
                this._inputFileName = Console.ReadLine();
            }

            Console.WriteLine("Enter the output file name: ");
            this._outputFileName = Console.ReadLine();

            try
            {
                // Open the input file for reading.
                StreamReader streamReader = new StreamReader(this._inputFileName);

                int    blockSize  = 100;
                char[] charBuffer = new char[blockSize];
                string stringBuffer;
                int    currentBlock = 0;

                // In order to ensure that all required DLLs to run the thread exist at each Executor
                // we must add a dependency to the Manifest for each DLL and/or file needed by the GThreads.
                gridApplication.Manifest.Add(new ModuleDependency(typeof(CustomGThread).Module));

                // Loop through the file reading blocks of size blockSize into the char[] array charBuffer
                // until we hit the end of the file.
                while (streamReader.ReadBlock(charBuffer, 0, blockSize) != 0)
                {
                    // ReadBlock returns a char[] buffer so convert it to a string to pass to our custom GThread.
                    stringBuffer = new string( charBuffer );

                    // Instantiate our custom GThread and pass the data we need to process through the constructor.
                    // Note: other methods of passing data to GThreads are possible.
                    CustomGThread customGThread = new CustomGThread(currentBlock, stringBuffer);

                    // Add the thread to the GApplication's Threads collection.
                    gridApplication.Threads.Add(customGThread);

                    currentBlock++;
                }

                // Close the input file.
                streamReader.Close();

                // Resize the output array to hold one entry per GThread.
                this._outputArray = new string[currentBlock];

                // Bind the ThreadFinished and ApplicationFinished events to local event handlers.
                gridApplication.ThreadFinish      += new GThreadFinish(gridApp_ThreadFinish);
                gridApplication.ApplicationFinish += new GApplicationFinish(gridApp_ApplicationFinish);

                // Start the GApplication.
                gridApplication.Start();

                Console.WriteLine("Application Started");
            }
            catch (Exception ex)
            {
                Console.WriteLine("An exception occurred: " + ex.Message + "\r\n" + ex.StackTrace);
            }
        }