Example #1
0
        /// <summary>Start a job to compute sigma</summary>
        /// <exception cref="System.IO.IOException"/>
        private void Compute(string name, Summation sigma)
        {
            if (sigma.GetValue() != null)
            {
                throw new IOException("sigma.getValue() != null, sigma=" + sigma);
            }
            //setup remote directory
            FileSystem fs  = FileSystem.Get(GetConf());
            Path       dir = fs.MakeQualified(new Path(parameters.remoteDir, name));

            if (!Org.Apache.Hadoop.Examples.PI.Util.CreateNonexistingDirectory(fs, dir))
            {
                return;
            }
            //setup a job
            Job  job    = CreateJob(name, sigma);
            Path outdir = new Path(dir, "out");

            FileOutputFormat.SetOutputPath(job, outdir);
            //start a map/reduce job
            string startmessage = "steps/parts = " + sigma.E.GetSteps() + "/" + parameters.nParts
                                  + " = " + Org.Apache.Hadoop.Examples.PI.Util.Long2string(sigma.E.GetSteps() / parameters
                                                                                           .nParts);

            Org.Apache.Hadoop.Examples.PI.Util.RunJob(name, job, parameters.machine, startmessage
                                                      , timer);
            IList <TaskResult> results = Org.Apache.Hadoop.Examples.PI.Util.ReadJobOutputs(fs,
                                                                                           outdir);

            Org.Apache.Hadoop.Examples.PI.Util.WriteResults(name, results, fs, parameters.remoteDir
                                                            );
            fs.Delete(dir, true);
            //combine results
            IList <TaskResult> combined = Org.Apache.Hadoop.Examples.PI.Util.Combine(results);
            PrintWriter        @out     = Org.Apache.Hadoop.Examples.PI.Util.CreateWriter(parameters.localDir
                                                                                          , name);

            try
            {
                foreach (TaskResult r in combined)
                {
                    string s = TaskResult2string(name, r);
                    @out.WriteLine(s);
                    @out.Flush();
                    [email protected](s);
                }
            }
            finally
            {
                @out.Close();
            }
            if (combined.Count == 1)
            {
                Summation s = combined[0].GetElement();
                if (sigma.Contains(s) && s.Contains(sigma))
                {
                    sigma.SetValue(s.GetValue());
                }
            }
        }
Example #2
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);
            }
        }
Example #3
0
        /// <summary>Write sigma to DataOutput</summary>
        /// <exception cref="System.IO.IOException"/>
        public static void Write(Summation sigma, DataOutput @out)
        {
            SummationWritable.ArithmeticProgressionWritable.Write(sigma.N, @out);
            SummationWritable.ArithmeticProgressionWritable.Write(sigma.E, @out);
            double v = sigma.GetValue();

            if (v == null)
            {
                @out.WriteBoolean(false);
            }
            else
            {
                @out.WriteBoolean(true);
                @out.WriteDouble(v);
            }
        }