Exemplo n.º 1
0
    static void Main(string[] args)
    {
        // 1. allocate a new dataflow computation.
        using (var computation = NewComputation.FromArgs(ref args))
        {
            if (args.Length != 5)
            {
                PrintHelp();
                return;
            }

            Int32 procid     = computation.Configuration.ProcessID;
            Int32 thread_num = computation.Configuration.WorkerCount;
            Int32 worker_num = computation.Configuration.Processes;

            Int32  dimension     = Int32.Parse(args[0]);
            Int32  iteration_num = Int32.Parse(args[1]);
            Int32  partition_num = Int32.Parse(args[2]);
            double sample_num_m  = Convert.ToDouble(args[3]);
            Int64  spin_wait     = Int64.Parse(args[4]);

            Console.Out.WriteLine("dimension: " + dimension);
            Console.Out.WriteLine("iteration_num: " + iteration_num);
            Console.Out.WriteLine("partition_num: " + partition_num);
            Console.Out.WriteLine("sample_num_m: " + sample_num_m);
            Console.Out.WriteLine("spin_wait: " + spin_wait);
            Console.Out.WriteLine("procid: " + procid);
            Console.Out.WriteLine("worker_num: " + worker_num);
            Console.Out.WriteLine("thread_num: " + thread_num);
            Console.Out.Flush();

            LogisticRegression lr =
                new LogisticRegression(dimension,
                                       iteration_num,
                                       partition_num,
                                       sample_num_m,
                                       spin_wait,
                                       procid,
                                       worker_num,
                                       thread_num);

            Stream <SampleBatch, Epoch> samples = lr.GenerateSamples().AsNaiadStream(computation);
            samples = samples.PartitionBy(s => (int)(s[0][0]));
            var end_samples = samples.Iterate((lc, s) => lr.Advance(s), iteration_num, "LogisticRegression");
            // var output = end_samples.Subscribe(x => {
            //                                           Console.Out.WriteLine("Final weight: " + PrintList(lr.weight_));
            //                                           Console.Out.Flush();
            //                                        });

            Console.Out.WriteLine("Before Activate!");
            Console.Out.Flush();
            // start the computation, fixing the structure of the dataflow graph.
            computation.Activate();
            Console.Out.WriteLine("After Activate!");
            Console.Out.Flush();

            // block until all work is finished.
            computation.Join();
            Console.Out.WriteLine("After Join!");


            double average_total   = lr.total_times_.GetRange(truncate_index_, iteration_num - truncate_index_).Average();
            double average_compute = lr.compute_times_.GetRange(truncate_index_, iteration_num - truncate_index_).Average();
            double average_idle    = average_total - average_compute;
            Console.Out.WriteLine("*** Average for the last {0:D2} iterations: compute(ms): {1:F2} total(ms): {2:F2} (idle(ms): {3:F2})",
                                  iteration_num - truncate_index_, 1000 * average_compute, 1000 * average_total, 1000 * average_idle);

            Console.Out.WriteLine("Final Weight: " + PrintList(lr.weight_));
            Console.Out.WriteLine("Samples Counts: " + PrintList(lr.sample_counter));
            Console.Out.WriteLine("Reduce Level 1 Counts: " + PrintList(lr.reduce_l1_counter_));
            Console.Out.WriteLine("Reduce Level 2 Counts: " + PrintList(lr.reduce_l2_counter_));
            Console.Out.WriteLine("Sync Level 1 Counts: " + PrintList(lr.sync_l1_counter_));
            Console.Out.WriteLine("Sync Level 2 Counts: " + PrintList(lr.sync_l2_counter_));
            Console.Out.WriteLine("Sync Tags: " + PrintHashSet(lr.sync_tags_));
            Console.Out.WriteLine("Reduce Tags: " + PrintHashSet(lr.reduce_tags_));
            Console.Out.WriteLine("Gradient Tags: " + PrintHashSet(lr.gradient_tags_));
            Console.Out.Flush();
        }
    }
Exemplo n.º 2
0
    static void Main(string[] args)
    {
        // 1. allocate a new dataflow computation.
        using (var computation = NewComputation.FromArgs(ref args))
        {
            if (args.Length != 5)
            {
                PrintHelp();
                return;
            }
            else if (args.Length == 1)
            {
                if (args[0] == "--help" || args[0] == "-h")
                {
                    PrintHelp();
                    return;
                }
            }


            Int32 procid        = computation.Configuration.ProcessID;
            Int32 dimension     = Int32.Parse(args[0]);
            Int32 iteration_num = Int32.Parse(args[1]);
            Int64 partition_num = Int32.Parse(args[2]);
            Int64 sample_num_m  = Int64.Parse(args[3]);
            Int64 worker_num    = Int64.Parse(args[4]);

            Console.Out.WriteLine("**NOTE: Worker num should be equal to core num!");
            Console.Out.WriteLine("procid: " + procid);
            Console.Out.WriteLine("dimension: " + dimension);
            Console.Out.WriteLine("iteration_num: " + iteration_num);
            Console.Out.WriteLine("partition_num: " + partition_num);
            Console.Out.WriteLine("sample_num_m: " + sample_num_m);
            Console.Out.WriteLine("worker_num (should be core num): " + worker_num);
            Console.Out.Flush();

            LogisticRegression lr =
                new LogisticRegression(procid,
                                       dimension,
                                       iteration_num,
                                       partition_num,
                                       sample_num_m,
                                       worker_num);

            Stream <Sample, Epoch> samples = lr.GenerateSamples().AsNaiadStream(computation);

            // partition the samples based on the first element.
            samples = samples.PartitionBy(s => (int)(s[0]));


            var end_samples = samples.Iterate((lc, s) => lr.Advance(s), iteration_num, "LogisticRegression");

            var output = end_samples.Subscribe(x => {
                Console.Out.WriteLine("Final weight: " + PrintList(lr.weight_));
                Console.Out.Flush();
            });

            Console.Out.WriteLine("Before Activate!");
            Console.Out.Flush();

            // start the computation, fixing the structure of the dataflow graph.
            computation.Activate();

            Console.Out.WriteLine("After Activate!");
            Console.Out.Flush();

            // block until all work is finished.
            computation.Join();

            Console.Out.WriteLine("After Join!");
            Console.Out.WriteLine("Counter 1 from procid: " + lr.procid_ + " " + PrintList(lr.counter_1_));
            Console.Out.WriteLine("Counter 2 from procid: " + lr.procid_ + " " + PrintList(lr.counter_2_));
            Console.Out.WriteLine("Counter 3 from procid: " + lr.procid_ + " " + PrintList(lr.counter_3_));
            Console.Out.Flush();
        }
    }