protected override void Setup(Mapper.Context context) { this.context = context; Configuration conf = context.GetConfiguration(); depth = conf.GetInt(Pentomino.Depth, PentDepth); width = conf.GetInt(Pentomino.Width, PentWidth); height = conf.GetInt(Pentomino.Height, PentHeight); pent = (Pentomino)ReflectionUtils.NewInstance(conf.GetClass(Pentomino.Class, typeof( OneSidedPentomino)), conf); pent.Initialize(width, height); pent.SetPrinter(new DistributedPentomino.PentMap.SolutionCatcher(this)); }
/// <exception cref="System.Exception"/> public virtual int Run(string[] args) { Configuration conf = GetConf(); if (args.Length == 0) { System.Console.Out.WriteLine("Usage: pentomino <output> [-depth #] [-height #] [-width #]" ); ToolRunner.PrintGenericCommandUsage(System.Console.Out); return(2); } // check for passed parameters, otherwise use defaults int width = conf.GetInt(Pentomino.Width, PentWidth); int height = conf.GetInt(Pentomino.Height, PentHeight); int depth = conf.GetInt(Pentomino.Depth, PentDepth); for (int i = 0; i < args.Length; i++) { if (Sharpen.Runtime.EqualsIgnoreCase(args[i], "-depth")) { depth = System.Convert.ToInt32(args[++i].Trim()); } else { if (Sharpen.Runtime.EqualsIgnoreCase(args[i], "-height")) { height = System.Convert.ToInt32(args[++i].Trim()); } else { if (Sharpen.Runtime.EqualsIgnoreCase(args[i], "-width")) { width = System.Convert.ToInt32(args[++i].Trim()); } } } } // now set the values within conf for M/R tasks to read, this // will ensure values are set preventing MAPREDUCE-4678 conf.SetInt(Pentomino.Width, width); conf.SetInt(Pentomino.Height, height); conf.SetInt(Pentomino.Depth, depth); Type pentClass = conf.GetClass <Pentomino>(Pentomino.Class, typeof(OneSidedPentomino )); int numMaps = conf.GetInt(MRJobConfig.NumMaps, DefaultMaps); Path output = new Path(args[0]); Path input = new Path(output + "_input"); FileSystem fileSys = FileSystem.Get(conf); try { Job job = Job.GetInstance(conf); FileInputFormat.SetInputPaths(job, input); FileOutputFormat.SetOutputPath(job, output); job.SetJarByClass(typeof(DistributedPentomino.PentMap)); job.SetJobName("dancingElephant"); Pentomino pent = ReflectionUtils.NewInstance(pentClass, conf); pent.Initialize(width, height); long inputSize = CreateInputDirectory(fileSys, input, pent, depth); // for forcing the number of maps FileInputFormat.SetMaxInputSplitSize(job, (inputSize / numMaps)); // the keys are the prefix strings job.SetOutputKeyClass(typeof(Text)); // the values are puzzle solutions job.SetOutputValueClass(typeof(Text)); job.SetMapperClass(typeof(DistributedPentomino.PentMap)); job.SetReducerClass(typeof(Reducer)); job.SetNumReduceTasks(1); return(job.WaitForCompletion(true) ? 0 : 1); } finally { fileSys.Delete(input, true); } }