示例#1
0
 static void allocateInRegion(int num_iterations, int num_objects,
                              string classType)
 {
     if (classType == "dict")
     {
         Console.WriteLine("Can not allocate dict in region.");
         return;
     }
     else if (classType == "list")
     {
         Int64        start  = RegionAllocator.NativeGetPerformanceCounter();
         Region       region = RegionAllocator.AllocateRegion(10000000);
         DeepListList d_list;
         for (int i = 0; i < num_iterations; i++)
         {
             d_list = new DeepListList(region, num_objects);
         }
         Int64 end = RegionAllocator.NativeGetPerformanceCounter();
         Print(end - start);
     }
     else
     {
         Console.WriteLine("Unexpected class type");
     }
 }
    public static void Main(string[] args)
    {
        var region = RegionAllocator.AllocateRegion(100);
        var obj    = new RegionClass(region);

        Console.WriteLine("{0}", obj.Increment());
    }
示例#3
0
 static void allocate(int num_iterations, int num_objects, string classType)
 {
     if (classType == "dict")
     {
         Int64 start = RegionAllocator.NativeGetPerformanceCounter();
         DeepDictionaryList d_dict;
         for (int i = 0; i < num_iterations; i++)
         {
             d_dict = new DeepDictionaryList(num_objects);
         }
         Int64 end = RegionAllocator.NativeGetPerformanceCounter();
         Print(end - start);
     }
     else if (classType == "list")
     {
         Int64        start = RegionAllocator.NativeGetPerformanceCounter();
         DeepListList d_list;
         for (int i = 0; i < num_iterations; i++)
         {
             d_list = new DeepListList(num_objects);
         }
         Int64 end = RegionAllocator.NativeGetPerformanceCounter();
         Print(end - start);
     }
     else
     {
         Console.WriteLine("Unexpected class type");
     }
 }
示例#4
0
        public static void Main(string[] args)
        {
            var region  = RegionAllocator.AllocateRegion(100);
            var testObj = new TestClass(region, 10);

            System.Console.WriteLine("Hi Mom!");
        }
示例#5
0
 public void onNotify(TTime time)
 {
     if (stateByTime.ContainsKey(time))
     {
         Region outputRegion =
             RegionAllocator.AllocateRegion(NaiadSimulator.OUTPUT_REGION_SIZE);
         var output =
             new Buffer <TTime, Pair <Integer, TState> >(outputRegion, time);
         int outputOffset = 0;
         using (RegionContext regContext = RegionContext.Create(outputRegion))
         {
             foreach (var pair in stateByTime[time])
             {
                 // Note: Automatically annotated code may require this Clone, but
                 // in the manually written one we don't need it.
                 // output.set(outputOffset,
                 //            new Pair<Integer, TState>((Integer)pair.Key.Clone(),
                 //                                      (TState)pair.Value.Clone()));
                 output.set(outputOffset,
                            new Pair <Integer, TState>(pair.Key, pair.Value));
                 outputOffset++;
             }
         }
         // The region will be freed.
         output.send(outputRegion);
         stateByTime.Remove(time);
         Region dictRegion = dictRegions[time];
         dictRegions.Remove(time);
         RegionAllocator.FreeRegion(dictRegion);
     }
 }
示例#6
0
        public ListActor(Region parentRegion)
        {
            var actorRegion = RegionAllocator.AllocateRegion(parentRegion, 100000);

            _list      = new RegionList <ItemList>(actorRegion);
            _recvCount = 0;
        }
示例#7
0
        public static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("Unexpected number of arguments. Please specify: num_threads num_iterations num_objects");
                return;
            }
            RegionAllocator.Initialize();
            int num_threads    = Convert.ToInt32(args[0]);
            int num_iterations = Convert.ToInt32(args[1]);
            int num_objects    = Convert.ToInt32(args[2]);

            Thread[] workerThreads = new Thread[num_threads];
            for (int i = 0; i < num_threads; ++i)
            {
                WorkerObject workerObject =
                    new WorkerObject(num_iterations, num_objects);
                workerThreads[i] = new Thread(workerObject.Allocate);
                workerThreads[i].Start();
            }
            for (int i = 0; i < num_threads; ++i)
            {
                workerThreads[i].Join();
            }
        }
        public static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Unexpected number of arguments. Please specify: num_contexts, num_repetitions");
                return;
            }
            RegionAllocator.Initialize();
            int    num_contexts    = Convert.ToInt32(args[0]);
            int    num_repetitions = Convert.ToInt32(args[1]);
            Region region          = RegionAllocator.AllocateRegion(4096);
            Int64  start;
            Int64  end;
            Int64  cycles = 0;

            for (int i = 0; i < num_repetitions; ++i)
            {
                start = RegionAllocator.NativeGetPerformanceCounter();
                using (RegionContext regContext = RegionContext.Create(region))
                {
                }
                end     = RegionAllocator.NativeGetPerformanceCounter();
                cycles += end - start;
            }
            Print(cycles / num_repetitions);
        }
示例#9
0
        public void Execute(string[] args)
        {
            int    windowSize  = 4;
            Region actorRegion =
                RegionAllocator.AllocateRegion(NaiadSimulator.ACTOR_REGION_SIZE);
            RegionWindowJoinVertex <Document, Author, int, JoinOutput> windowJoinVertex;

            using (RegionContext regContext = RegionContext.Create(actorRegion))
            {
                windowJoinVertex =
                    new RegionWindowJoinVertex <Document, Author, int, JoinOutput>(
                        windowSize,
                        document => document.authorId,
                        author => author.id,
                        (document, author) => new JoinOutput(document.title,
                                                             author.name,
                                                             author.age));
                // Note: Depending on how we use batching we may or may not have to
                // clone the fields.
                // (document, author) => new JoinOutput(String.Copy(document.title),
                //                                      String.Copy(author.name),
                //                                      author.age));
            }
            PlayData(windowJoinVertex, args[0], args[1], actorRegion);
            RegionAllocator.FreeRegion(actorRegion);
        }
示例#10
0
    public static void Main(string[] args) {
      RegionAllocator.Initialize();
      for (int i = 0; i < 50; ++i)
      {
        var region = RegionAllocator.AllocateRegion(100000);
        using (RegionContext regContext = RegionContext.Create(region))
        {
//          List<TestClass> objList = new List<TestClass>();
          RegionLinkedList<TestClass> objList = new RegionLinkedList<TestClass>();
          //Dictionary<int, TestClass> objDict = new Dictionary<int, TestClass>();
          for (int j = 0; j < 2; ++j)
          {
//            objList.Add(new TestClass(region, 10));
            objList.InsertFirst(new TestClass(10));
//            objList.InsertFirst(region, new TestClass(region, 10));
//            objDict.Add(j, new TestClass(10));
          }
        }
        RegionAllocator.FreeRegion(region);
        if (i % 10 == 0)
        {
          GC.Collect();
        }
      }
    }
示例#11
0
        public void PlayDataFromMemory(AggregateVertex <AggDocument, int> aggVertex,
                                       string filename)
        {
            int time_epoch = 0;
            RegionLinkedList <Message <int, Pair <Integer, AggDocument> > > messages;

            using (StreamReader file = File.OpenText(filename))
            {
                Region inputRegion =
                    RegionAllocator.AllocateRegion(NaiadSimulator.TMP_REGION_SIZE);
                using (RegionContext regContext = RegionContext.Create(inputRegion))
                {
                    messages =
                        new RegionLinkedList <Message <int, Pair <Integer, AggDocument> > >();
                    while (true)
                    {
                        var line = file.ReadLine();
                        if (line == null)
                        {
                            break;
                        }
                        var elements = line.Split(' ');
                        if (elements[0] == "BEGIN")
                        {
                            int time       = Convert.ToInt32(elements[1]);
                            int batch_size = Convert.ToInt32(elements[2]);
                            Message <int, Pair <Integer, AggDocument> > msg =
                                new Message <int, Pair <Integer, AggDocument> >(time, batch_size);
                            for (int i = 0; i < batch_size; i++)
                            {
                                elements = file.ReadLine().Split(' ');
                                msg.put(new Pair <Integer, AggDocument>(
                                            new Integer(Convert.ToInt32(elements[3])),
                                            new AggDocument(new Integer(Convert.ToInt32(elements[1])),
                                                            new Integer(Convert.ToInt32(elements[2])),
                                                            new Integer(Convert.ToInt32(elements[3])),
                                                            elements[4])));
                            }
                            messages.InsertFirst(msg);
                            time_epoch++;
                        }
                    }
                }
            }
            Int64 start = RegionAllocator.NativeGetPerformanceCounter();

            for (Node <Message <int, Pair <Integer, AggDocument> > > cur = messages.Head;
                 cur != default(Node <Message <int, Pair <Integer, AggDocument> > >);
                 cur = cur.Next)
            {
                aggVertex.onReceive((Message <int, Pair <Integer, AggDocument> >)cur.Data.Clone());
                aggVertex.onNotify(--time_epoch);
            }
            // NOTE: We do not free the input region because we don't want to include
            // it in measuring the runtime. The input region is just used as a
            // mechanism to load the data into memory.
            Int64 end = RegionAllocator.NativeGetPerformanceCounter();

            Utils.Print(end - start);
        }
示例#12
0
        public static void Main(string[] args)
        {
            RegionAllocator.Initialize();
            if (args.Length != 1)
            {
                Console.WriteLine("Unexpected number of arguments. Please specify: num_regions");
                return;
            }
            int num_regions = Convert.ToInt32(args[0]);

            Region[] regions = new Region[num_regions];
            for (int i = 0; i < num_regions; ++i)
            {
                regions[i] = RegionAllocator.AllocateRegion(10000);
            }
            Region region = RegionAllocator.AllocateRegion(10000);

            using (RegionContext regContext = RegionContext.Create(region))
            {
                for (int i = 0; i < num_regions; ++i)
                {
                    RegionAllocator.FreeRegion(regions[i]);
                }
            }
            Region failedRegion = RegionAllocator.AllocateRegion(10000);

            Console.WriteLine("Finish");
        }
示例#13
0
 public void onNotify(TTime time)
 {
     if (vals.ContainsKey(time))
     {
         Region outputRegion =
             RegionAllocator.AllocateRegion(NaiadSimulator.OUTPUT_REGION_SIZE);
         var output =
             new Buffer <TTime, PairNonCloneable <TKey, RegionLinkedList <TInput> > >(outputRegion, time);
         int outputOffset = 0;
         using (RegionContext regContext = RegionContext.Create(outputRegion))
         {
             foreach (var group in vals[time])
             {
                 // NOTE: In real Naiad we might have to copy the pair.
                 output.set(outputOffset,
                            new PairNonCloneable <TKey, RegionLinkedList <TInput> >(group.Key, group.Value));
                 outputOffset++;
             }
         }
         output.send(outputRegion);
         vals.Remove(time);
         Region dictRegion = dictRegions[time];
         dictRegions.Remove(time);
         RegionAllocator.FreeRegion(dictRegion);
     }
 }
示例#14
0
        public void onReceive(Message <TTime, TInput> message)
        {
            Region outputRegion =
                RegionAllocator.AllocateRegion(NaiadSimulator.OUTPUT_REGION_SIZE);
            var output       = new Buffer <TTime, TOutput>(outputRegion, message.time);
            int outputOffset = 0;

            TInput input;

            using (RegionContext regContext = RegionContext.Create(outputRegion))
            {
                for (int i = 0; i < message.length; i++)
                {
                    // Note: Automatically annotated code may require this Clone, but
                    // in the manually written one we don't need it.
                    // input = (TInput)message.payload[i].Clone();
                    input = message.payload[i];
                    foreach (var res in this.function(input))
                    {
                        output.set(outputOffset, res);
                        outputOffset++;
                    }
                }
            }
            // The region will be freed.
            output.send(outputRegion);
        }
示例#15
0
        public void Execute(string[] args)
        {
            Region actorRegion =
                RegionAllocator.AllocateRegion(NaiadSimulator.ACTOR_REGION_SIZE);
            RegionAggregateVertex <AggDocument, int> aggregateVertex;

            using (RegionContext regContext = RegionContext.Create(actorRegion))
            {
                aggregateVertex =
                    new RegionAggregateVertex <AggDocument, int>(
                        (accDoc, newDoc) => new AggDocument(accDoc.docId,
                                                            accDoc.length + newDoc.length,
                                                            accDoc.authorId,
                                                            accDoc.title));
                // Note: Depending on how we use batching we may or may not have to
                // clone the fields.
                // (accDoc, newDoc) => new AggDocument(new Integer(accDoc.docId),
                //                                     accDoc.length + newDoc.length,
                //                                     new Integer(accDoc.authorId),
                //                                     String.Copy(accDoc.title)));
            }
            PlayData(aggregateVertex, args[0], actorRegion);
            // PlayDataFromMemory(aggregateVertex, args[0], actorRegion);
            RegionAllocator.FreeRegion(actorRegion);
        }
示例#16
0
 public static void WarmAllocRegions(uint num_regions, uint region_size)
 {
     for (int i = 0; i < num_regions; i++)
     {
         RegionAllocator.AllocateRegion(region_size);
     }
 }
示例#17
0
        public void onNotify(TTime time)
        {
            vals.Remove(time);
            Region region = dictRegions[time];

            dictRegions.Remove(time);
            RegionAllocator.FreeRegion(region);
        }
示例#18
0
 public static void WarmFreeList(uint num_regions, uint region_size)
 {
     for (int i = 0; i < num_regions; i++)
     {
         Region region = RegionAllocator.AllocateRegion(region_size);
         RegionAllocator.FreeRegion(region);
     }
 }
示例#19
0
        public static void Main(string[] args)
        {
            Random random     = new Random();
            string general    = "teststringisgettingbiggerandbiggerit'salreadybigdata";
            int    generalLen = general.Length;

            if (args.Length != 3)
            {
                Console.WriteLine("Please supply arguments: gen0|gen1 region|nonregion|regioncontext number_inner_iterations");
                return;
            }
            RegionAllocator.Initialize();
            int num_iterations = Convert.ToInt32(args[2]);

            if (args[0] == "gen0")
            {
                if (args[1] == "region")
                {
                    AllocateInnerLoopRegion(num_iterations, general);
                }
                else if (args[1] == "regioncontext")
                {
                    AllocateInnerLoopRegionContext(num_iterations, general);
                }
                else if (args[1] == "nonregion")
                {
                    AllocateInnerLoop(num_iterations, general);
                }
                else
                {
                    Console.WriteLine("Unexpected argument");
                }
            }
            else if (args[0] == "gen1")
            {
                if (args[1] == "region")
                {
                    AllocateInnerOuterLoopRegion(num_iterations, general);
                }
                else if (args[1] == "regioncontext")
                {
                    AllocateInnerOuterLoopRegionContext(num_iterations, general);
                }
                else if (args[1] == "nonregion")
                {
                    AllocateInnerOuterLoop(num_iterations, general);
                }
                else
                {
                    Console.WriteLine("Unexpected argument");
                }
            }
            else
            {
                Console.WriteLine("Unexpected argument");
            }
        }
        public static void Print(double cycles)
        {
            Int64 frequency = RegionAllocator.NativeGetPerformanceFrequency();

            Console.WriteLine("Cycles: {0}\n", cycles);
            cycles *= 1000000000.0;
            double duration = cycles / (double)frequency;

            Console.WriteLine("Time(ns): {0}\n", duration);
        }
示例#21
0
 public void onNotify(int time)
 {
     // TODO(ionel): This doesn't free the last windowSize regions.
     if (time - windowSize >= 0)
     {
         vals.Remove(time - windowSize);
         Region region = dictRegions[time - windowSize];
         dictRegions.Remove(time - windowSize);
         RegionAllocator.FreeRegion(region);
     }
 }
        public static void Main(string[] args)
        {
            var region      = RegionAllocator.AllocateRegion(10000);
            var firstObject = new FirstType(region);

            firstObject.TestCall();
            var secondObject = new SecondType(region);

            firstObject.TestCall();
            secondObject.TestCall();
        }
示例#23
0
 public static void AllocateInnerLoopRegion(int num_iterations,
                                            string general)
 {
     for (int i = 0; i < 100; ++i)
     {
         var region = RegionAllocator.AllocateRegion(40000000);
         for (int j = 0; j < num_iterations; ++j)
         {
             TestClass testObj = new TestClass(region, general);
         }
         RegionAllocator.FreeRegion(region);
     }
 }
示例#24
0
        public static void Main(string[] args)
        {
            var parentRegion = RegionAllocator.AllocateRegion(320000);
            var actor        = new ListActor(parentRegion);

            Console.WriteLine("Allocated parent region");
            for (int count = 0; count < 10000; count++)
            {
                var messageRegion = RegionAllocator.AllocateRegion(parentRegion, 2000000);
                var itemList      = new ItemList(messageRegion);
                actor.OnRecv(itemList);
            }
        }
示例#25
0
        static void StressRegionContext(int num_iterations)
        {
            Region region = RegionAllocator.AllocateRegion(1000);

            for (int i = 0; i < num_iterations; i++)
            {
                using (RegionContext regContext = RegionContext.Create(region))
                {
                }
                // TODO(ionel): Make sure that the region doesn't get freed at the end
                // of the using.
            }
        }
示例#26
0
 public void PlayData(RegionAggregateVertex <AggDocument, int> aggVertex,
                      string filename, Region actorRegion)
 {
     if (File.Exists(filename))
     {
         using (StreamReader file = File.OpenText(filename))
         {
             while (true)
             {
                 var line = file.ReadLine();
                 if (line == null)
                 {
                     break;
                 }
                 Region inputRegion =
                     RegionAllocator.AllocateRegion(NaiadSimulator.TMP_REGION_SIZE);
                 using (RegionContext regContext = RegionContext.Create(inputRegion))
                 {
                     var elements = line.Split(' ');
                     if (elements[0] == "BEGIN")
                     {
                         int time       = Convert.ToInt32(elements[1]);
                         int batch_size = Convert.ToInt32(elements[2]);
                         Message <int, Pair <Integer, AggDocument> > msg =
                             new Message <int, Pair <Integer, AggDocument> >(time, batch_size);
                         for (int i = 0; i < batch_size; i++)
                         {
                             elements = file.ReadLine().Split(' ');
                             msg.put(new Pair <Integer, AggDocument>(
                                         new Integer(Convert.ToInt32(elements[3])),
                                         new AggDocument(new Integer(Convert.ToInt32(elements[1])),
                                                         new Integer(Convert.ToInt32(elements[2])),
                                                         new Integer(Convert.ToInt32(elements[3])),
                                                         elements[4])));
                         }
                         aggVertex.onReceive(msg, actorRegion);
                     }
                     else if (elements[0] == "END")
                     {
                         aggVertex.onNotify(Convert.ToInt32(elements[1]));
                     }
                 }
                 RegionAllocator.FreeRegion(inputRegion);
             }
         }
     }
     else
     {
         Console.WriteLine("Input file does not exist");
     }
 }
示例#27
0
        // The region will be freed.
        public void send(Region region)
        {
            // Message<TTime, TRecord> msg =
            //   new Message<TTime, TRecord>(region, id, size);
            // for (int i = 0; i < size; i++)
            // {
            //   msg.put(memory_block[i]);
            // }
#if DEBUG
            print();
            Console.WriteLine("DONE");
#endif
            RegionAllocator.FreeRegion(region);
        }
示例#28
0
        public static void Allocate(int num_objects)
        {
            Int64     start;
            Int64     end;
            TestClass obj;

            start = RegionAllocator.NativeGetPerformanceCounter();
            for (int i = 0; i < num_objects; ++i)
            {
                obj = new TestClass(1);
            }
            end = RegionAllocator.NativeGetPerformanceCounter();
            Console.WriteLine("--- Allocate on the heap ---");
            Print(end - start);
        }
示例#29
0
        public void Execute(string[] args)
        {
            Region actorRegion =
                RegionAllocator.AllocateRegion(NaiadSimulator.ACTOR_REGION_SIZE);
            RegionGroupByVertex <Document, int, int> groupByVertex;

            using (RegionContext regContext = RegionContext.Create(actorRegion))
            {
                groupByVertex =
                    new RegionGroupByVertex <Document, int, int>(
                        document => document.authorId);
            }
            PlayData(groupByVertex, args[0], actorRegion);
            RegionAllocator.FreeRegion(actorRegion);
        }
示例#30
0
 public static void AllocateInnerLoopRegionContext(int num_iterations,
                                                   string general)
 {
     for (int i = 0; i < 100; ++i)
     {
         var region = RegionAllocator.AllocateRegion(40000000);
         using (RegionContext regContext = RegionContext.Create(region))
         {
             for (int j = 0; j < num_iterations; ++j)
             {
                 TestClass testObj = new TestClass(region, general);
             }
         }
     }
 }