Ejemplo n.º 1
0
        /// <summary>
        /// <inheritDoc/>
        ///
        /// </summary>
        /// <exception cref="System.Exception"/>
        public int Run(string[] args)
        {
            //parse arguments
            if (args.Length != DistSum.Parameters.Count + 2)
            {
                return(Org.Apache.Hadoop.Examples.PI.Util.PrintUsage(args, GetType().FullName + " <name> <sigma> "
                                                                     + DistSum.Parameters.List + "\n  <name> The name." + "\n  <sigma> The summation."
                                                                     + DistSum.Parameters.Description));
            }
            int       i     = 0;
            string    name  = args[i++];
            Summation sigma = Summation.ValueOf(args[i++]);

            SetParameters(DistSum.Parameters.Parse(args, i));
            [email protected]();
            [email protected]("name  = " + name);
            [email protected]("sigma = " + sigma);
            [email protected](parameters);
            [email protected]();
            //run jobs
            Summation result = Execute(name, sigma);

            if (result.Equals(sigma))
            {
                sigma.SetValue(result.GetValue());
                timer.Tick("\n\nDONE\n\nsigma=" + sigma);
                return(0);
            }
            else
            {
                timer.Tick("\n\nDONE WITH ERROR\n\nresult=" + result);
                return(1);
            }
        }
Ejemplo n.º 2
0
        /// <summary>Execute DistSum computations</summary>
        /// <exception cref="System.Exception"/>
        private void Execute(DistSum distsum, IDictionary <Bellard.Parameter, Bellard.Sum>
                             sums)
        {
            IList <DistSum.Computation> computations = new AList <DistSum.Computation>();
            int i = 0;

            foreach (Bellard.Parameter p in Bellard.Parameter.Values())
            {
                foreach (Summation s in sums[p])
                {
                    if (s.GetValue() == null)
                    {
                        computations.AddItem(new DistSum.Computation(this, i++, p.ToString(), s));
                    }
                }
            }
            if (computations.IsEmpty())
            {
                [email protected]("No computation");
            }
            else
            {
                timer.Tick("execute " + computations.Count + " computation(s)");
                Org.Apache.Hadoop.Examples.PI.Util.Execute(distsum.GetParameters().nThreads, computations
                                                           );
                timer.Tick("done");
            }
        }
Ejemplo n.º 3
0
        /// <summary>Run a job.</summary>
        internal static void RunJob(string name, Job job, DistSum.Machine machine, string
                                    startmessage, Util.Timer timer)
        {
            JobSemaphore.AcquireUninterruptibly();
            long starttime = null;

            try
            {
                try
                {
                    starttime = timer.Tick("starting " + name + " ...\n  " + startmessage);
                    //initialize and submit a job
                    machine.Init(job);
                    job.Submit();
                    // Separate jobs
                    long sleeptime = 1000L * job.GetConfiguration().GetInt(JobSeparationProperty, 10);
                    if (sleeptime > 0)
                    {
                        [email protected](name + "> sleep(" + Org.Apache.Hadoop.Examples.PI.Util
                                                                          .Millis2String(sleeptime) + ")");
                        Sharpen.Thread.Sleep(sleeptime);
                    }
                }
                finally
                {
                    JobSemaphore.Release();
                }
                if (!job.WaitForCompletion(false))
                {
                    throw new RuntimeException(name + " failed.");
                }
            }
            catch (Exception e)
            {
                throw e is RuntimeException ? (RuntimeException)e : new RuntimeException(e);
            }
            finally
            {
                if (starttime != null)
                {
                    timer.Tick(name + "> timetaken=" + Org.Apache.Hadoop.Examples.PI.Util.Millis2String
                                   (timer.Tick() - starttime));
                }
            }
        }