Esempio n. 1
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);
        }
        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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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();
        }
      }
    }
Esempio n. 5
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);
        }
Esempio n. 6
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");
        }
Esempio n. 7
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);
     }
 }
Esempio n. 8
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);
     }
 }
Esempio n. 9
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);
        }
Esempio n. 10
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.
            }
        }
Esempio n. 11
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");
     }
 }
Esempio n. 12
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);
             }
         }
     }
 }
Esempio n. 13
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);
        }
Esempio n. 14
0
 public void Allocate()
 {
     for (int i = 0; i < num_iterations; ++i)
     {
         var region = RegionAllocator.AllocateRegion(100000);
         using (RegionContext regContext = RegionContext.Create(region))
         {
             List <TestClass> objList = new List <TestClass>();
             for (int j = 0; j < num_objects; ++j)
             {
                 objList.Add(new TestClass(region, 10));
             }
             RegionAllocator.FreeRegion(region);
         }
     }
 }
Esempio n. 15
0
        public static void AllocateInRegionContext(Region region, int num_objects)
        {
            Int64     start;
            Int64     end;
            TestClass obj;

            start = RegionAllocator.NativeGetPerformanceCounter();
            using (RegionContext regContext = RegionContext.Create(region))
            {
                for (int i = 0; i < num_objects; ++i)
                {
                    obj = new TestClass(1);
                }
            }
            end = RegionAllocator.NativeGetPerformanceCounter();
            Console.WriteLine("--- Allocate using the regioncontext ---");
            Print(end - start);
        }
Esempio n. 16
0
        public void onReceive(Message <TTime, Pair <Integer, TState> > message,
                              Region actorRegion)
        {
            Region dictRegion;

            if (!stateByTime.ContainsKey(message.time))
            {
                dictRegion =
                    RegionAllocator.AllocateRegion(NaiadSimulator.TMP_REGION_SIZE);
                Dictionary <Integer, TState> dictKeyState;
                using (RegionContext regContext = RegionContext.Create(dictRegion))
                {
                    dictKeyState =
                        new Dictionary <Integer, TState>(0, new IntegerEqualityComparer());
                }
                using (RegionContext regContext = RegionContext.Create(actorRegion))
                {
                    stateByTime.Add(message.time, dictKeyState);
                    dictRegions.Add(message.time, dictRegion);
                }
            }
            var states = stateByTime[message.time];

            dictRegion = dictRegions[message.time];

            using (RegionContext regContext = RegionContext.Create(dictRegion))
            {
                Pair <Integer, TState> inputPair;
                for (int i = 0; i < message.length; i++)
                {
                    inputPair = (Pair <Integer, TState>)message.payload[i].Clone();
                    var key = inputPair.First;

                    if (!states.ContainsKey(key))
                    {
                        states.Add(key, inputPair.Second);
                    }
                    else
                    {
                        states[key] = combiner(states[key], inputPair.Second);
                    }
                }
            }
        }
Esempio n. 17
0
        public void PlayData(RegionWindowJoinVertex <Document, Author, int, JoinOutput> vertex,
                             string docFileName, string authorFileName,
                             Region actorRegion)
        {
            if (File.Exists(docFileName) && File.Exists(authorFileName))
            {
                using (StreamReader docFile = File.OpenText(docFileName))
                {
                    using (StreamReader authorFile = File.OpenText(authorFileName))
                    {
                        bool   docEmpty    = false;
                        bool   authorEmpty = false;
                        Region inputRegion =
                            RegionAllocator.AllocateRegion(NaiadSimulator.TMP_REGION_SIZE);
                        using (RegionContext regContext = RegionContext.Create(inputRegion))
                        {
                            while (!docEmpty || !authorEmpty)
                            {
                                var line = docFile.ReadLine();
                                if (line != null)
                                {
                                    ReadDocBatch(docFile, line, vertex, actorRegion);
                                }
                                else
                                {
                                    docEmpty = true;
                                }

                                line = authorFile.ReadLine();
                                if (line != null)
                                {
                                    ReadAuthorBatch(authorFile, line, vertex, actorRegion);
                                }
                                else
                                {
                                    authorEmpty = true;
                                }
                            }
                        }
                        RegionAllocator.FreeRegion(inputRegion);
                    }
                }
            }
        }
Esempio n. 18
0
        public static void Main(string[] args)
        {
            RegionAllocator.Initialize();
            Console.WriteLine("Allocating region");
            System.Diagnostics.Debugger.Break();
            var region = RegionAllocator.AllocateRegion(10000);

            Console.WriteLine("Allocated region");

            using (var c = RegionContext.Create(region))
            {
                Console.WriteLine("Created region context");
                var dictionary = new Dictionary <int, int>();
                dictionary.Add(10, 10);
                Console.WriteLine("{0}", dictionary[10]);
            }

            RegionAllocator.FreeRegion(region);
        }
Esempio n. 19
0
        static void Main(string[] args)
        {
            RegionAllocator.Initialize();
            Region outerRegion = RegionAllocator.AllocateRegion(10000);
            Region otherRegion = RegionAllocator.AllocateRegion(10000);

            using (RegionContext outerContext = RegionContext.Create(outerRegion))
            {
                Region innerRegion = RegionAllocator.AllocateRegion(10000);
                using (RegionContext innerContext = RegionContext.Create(innerRegion))
                {
                }
                using (RegionContext otherContext = RegionContext.Create(otherRegion))
                {
                }
                using (RegionContext innerContext = RegionContext.Create(innerRegion))
                {
                }
            }
        }
Esempio n. 20
0
        public static void Main(string[] args)
        {
            var region  = RegionAllocator.AllocateRegion(10000);
            var region2 = RegionAllocator.AllocateRegion(10000);

            using (RegionContext regContext = RegionContext.Create(region))
            {
                var testObjReg2    = new TestClass(region2, 12);
                var testobjContext = new TestClass(11);
            }
            RegionAllocator.FreeRegion(region2);
            var testObjReg  = new TestClass(region, 10);
            var testObjHeap = new TestClass(10);

            GC.Collect();
            var region3     = RegionAllocator.AllocateRegion(9000);
            var testObjReg3 = new TestClass(region3, 15);

            GC.Collect();
        }
Esempio n. 21
0
        static void Main(string[] args)
        {
            RegionAllocator.Initialize();
            if (args.Length != 2)
            {
                Console.WriteLine("Please specify: empty_stack|non_empty_stack num_iterations");
            }
            int num_iterations = Convert.ToInt32(args[1]);

            if (args[0] == "non_empty_stack")
            {
                Region outerRegion = RegionAllocator.AllocateRegion(1000);
                using (RegionContext outerRegCxt = RegionContext.Create(outerRegion))
                {
                    StressRegionContext(num_iterations);
                }
            }
            else
            {
                StressRegionContext(num_iterations);
            }
        }
Esempio n. 22
0
        static void allocateInRegionContext(int num_iterations, int num_objects,
                                            string classType)
        {
            Region region = RegionAllocator.AllocateRegion(10000000);

            if (classType == "dict")
            {
                Int64 start = RegionAllocator.NativeGetPerformanceCounter();
                using (RegionContext regContext = RegionContext.Create(region))
                {
                    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();
                using (RegionContext regContext = RegionContext.Create(region))
                {
                    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");
            }
        }
Esempio n. 23
0
        public void onReceive(Message <TTime, TInput> message, Region actorRegion)
        {
            Region dictRegion;

            if (!vals.ContainsKey(message.time))
            {
                Dictionary <TKey, RegionLinkedList <TInput> > dictKeyList;
                dictRegion =
                    RegionAllocator.AllocateRegion(NaiadSimulator.TMP_REGION_SIZE);
                using (RegionContext regContext = RegionContext.Create(dictRegion))
                {
                    dictKeyList = new Dictionary <TKey, RegionLinkedList <TInput> >();
                }
                using (RegionContext regContext = RegionContext.Create(actorRegion))
                {
                    vals.Add(message.time, dictKeyList);
                    dictRegions.Add(message.time, dictRegion);
                }
            }
            var dictGroup = vals[message.time];

            dictRegion = dictRegions[message.time];

            using (RegionContext regContext = RegionContext.Create(dictRegion))
            {
                TInput input;
                for (int i = 0; i < message.length; i++)
                {
                    input = (TInput)message.payload[i].Clone();
                    var key = keySelector(input);
                    if (!dictGroup.ContainsKey(key))
                    {
                        dictGroup.Add(key, new RegionLinkedList <TInput>());
                    }
                    dictGroup[key].InsertFirst(input);
                }
            }
        }
Esempio n. 24
0
        public static void Main(string[] args)
        {
            RegionAllocator.Initialize();
            var tinyRegion = RegionAllocator.AllocateRegion(500);

            for (int i = 0; i < 100; i++)
            {
                TestClass obj = new TestClass(tinyRegion, 10);
            }

            using (var context = RegionContext.Create(tinyRegion))
            {
                char[] alphabet = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' };
                for (int i = 0; i < 100; i++)
                {
                    string alpha = new string(alphabet);
                }
            }

            RegionAllocator.FreeRegion(tinyRegion);

            Console.WriteLine("Finish");
        }
Esempio n. 25
0
 public static void AllocateInnerOuterLoopRegion(int num_iterations,
                                                 string general)
 {
     // NOTE: This does quite implement the same behaviour as
     // AllocateInnerOuterLoop
     for (int i = 0; i < 100; ++i)
     {
         var longRegion = RegionAllocator.AllocateRegion(40000000);
         using (RegionContext regContext = RegionContext.Create(longRegion))
         {
             TestClass[] objList = new TestClass[100000];
             for (int j = 0; j < 100000; ++j)
             {
                 objList[j] = new TestClass(longRegion, general);
             }
         }
         var region = RegionAllocator.AllocateRegion(40000000);
         for (int j = 0; j < num_iterations; ++j)
         {
             TestClass testObj = new TestClass(region, general);
         }
         RegionAllocator.FreeRegion(region);
     }
 }
Esempio n. 26
0
 public static void AllocateInnerOuterLoopRegionContext(int num_iterations,
                                                        string general)
 {
     for (int i = 0; i < 100; ++i)
     {
         var longRegion = RegionAllocator.AllocateRegion(40000000);
         using (RegionContext outerRegContext = RegionContext.Create(longRegion))
         {
             TestClass[] objList = new TestClass[100000];
             for (int j = 0; j < 100000; ++j)
             {
                 objList[j] = new TestClass(general);
             }
             var region = RegionAllocator.AllocateRegion(40000000);
             using (RegionContext regContext = RegionContext.Create(region))
             {
                 for (int j = 0; j < num_iterations; ++j)
                 {
                     TestClass testObj = new TestClass(general);
                 }
             }
         }
     }
 }
        public static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("Unexpected number of arguments. Please specify: size_of_region num_repetitions region|nonregion|regioncontext");
                return;
            }
            RegionAllocator.Initialize();
            uint      size_of_region  = (uint)Convert.ToInt32(args[0]);
            int       num_repetitions = Convert.ToInt32(args[1]);
            Region    region          = RegionAllocator.AllocateRegion(size_of_region);
            Int64     start;
            Int64     end;
            Int64     cycles = 0;
            TestClass obj;

            if (args[2] == "nonregion")
            {
                for (int i = 0; i < num_repetitions; ++i)
                {
                    start   = RegionAllocator.NativeGetPerformanceCounter();
                    obj     = new TestClass(1);
                    end     = RegionAllocator.NativeGetPerformanceCounter();
                    cycles += end - start;
                }
                Console.WriteLine("--- Allocate on the heap ---");
                Print((double)cycles / (double)num_repetitions);
            }
            else if (args[2] == "region")
            {
                for (int i = 0; i < num_repetitions; ++i)
                {
                    start   = RegionAllocator.NativeGetPerformanceCounter();
                    obj     = new TestClass(region, 1);
                    end     = RegionAllocator.NativeGetPerformanceCounter();
                    cycles += end - start;
                }

                Console.WriteLine("--- Allocate in the region ---");
                Print((double)cycles / (double)num_repetitions);
            }
            else if (args[2] == "regioncontext")
            {
                for (int i = 0; i < num_repetitions; ++i)
                {
                    using (RegionContext regContext = RegionContext.Create(region))
                    {
                        start = RegionAllocator.NativeGetPerformanceCounter();
                        obj   = new TestClass(1);
                        end   = RegionAllocator.NativeGetPerformanceCounter();
                    }
                    cycles += end - start;
                }

                Console.WriteLine("--- Allocate in the region using a context ---");
                Print((double)cycles / (double)num_repetitions);
            }
            else
            {
                Console.WriteLine("Unexpected option");
            }
        }
Esempio n. 28
0
        public void PlayDataFromMemory(JoinVertex <Document, Author, int, JoinOutput, int> joinVertex,
                                       string docFileName, string authorFileName)
        {
            int timeEpoch = 0;
            RegionLinkedList <Message <int, Document> > msgsDocs;
            RegionLinkedList <Message <int, Author> >   msgsAuthors;

            using (StreamReader docFile = File.OpenText(docFileName))
            {
                using (StreamReader authorFile = File.OpenText(authorFileName))
                {
                    Region inputRegion =
                        RegionAllocator.AllocateRegion(NaiadSimulator.TMP_REGION_SIZE);
                    using (RegionContext regContext = RegionContext.Create(inputRegion))
                    {
                        bool docEmpty    = false;
                        bool authorEmpty = false;
                        msgsDocs    = new RegionLinkedList <Message <int, Document> >();
                        msgsAuthors = new RegionLinkedList <Message <int, Author> >();
                        while (!docEmpty || !authorEmpty)
                        {
                            var line = docFile.ReadLine();
                            if (line != null)
                            {
                                var elements = line.Split(' ');
                                if (elements[0] == "BEGIN")
                                {
                                    timeEpoch++;
                                    msgsDocs.InsertFirst(ReadUtils.ReadDocBatchMemory(docFile, line));
                                }
                            }
                            else
                            {
                                docEmpty = true;
                            }

                            line = authorFile.ReadLine();
                            if (line != null)
                            {
                                var elements = line.Split(' ');
                                if (elements[0] == "BEGIN")
                                {
                                    msgsAuthors.InsertFirst(ReadUtils.ReadAuthorBatchMemory(authorFile, line));
                                }
                            }
                            else
                            {
                                authorEmpty = true;
                            }
                        }
                    }
                }
            }
            Int64 start = RegionAllocator.NativeGetPerformanceCounter();
            Node <Message <int, Document> > curDocs    = msgsDocs.Head;
            Node <Message <int, Author> >   curAuthors = msgsAuthors.Head;

            while (curDocs != default(Node <Message <int, Document> >) &&
                   curAuthors != default(Node <Message <int, Author> >))
            {
                joinVertex.onReceive((Message <int, Document>)curDocs.Data.Clone());
                joinVertex.onReceive((Message <int, Author>)curAuthors.Data.Clone());
                joinVertex.onNotify(--timeEpoch);
                curDocs    = curDocs.Next;
                curAuthors = curAuthors.Next;
            }

            // 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);
        }
Esempio n. 29
0
        public void onReceive(Message <TTime, TInput2> message, Region actorRegion)
        {
            Region outputRegion =
                RegionAllocator.AllocateRegion(NaiadSimulator.OUTPUT_REGION_SIZE);
            var output       = new Buffer <TTime, TOutput>(outputRegion, message.time);
            int outputOffset = 0;

            Region dictRegion;

            if (!vals.ContainsKey(message.time))
            {
                Dictionary <TKey, PairNonCloneable <RegionLinkedList <TInput1>, RegionLinkedList <TInput2> > > dictKeyPair;
                dictRegion =
                    RegionAllocator.AllocateRegion(NaiadSimulator.TMP_REGION_SIZE);
                using (RegionContext regContext = RegionContext.Create(dictRegion))
                {
                    dictKeyPair =
                        new Dictionary <TKey, PairNonCloneable <RegionLinkedList <TInput1>, RegionLinkedList <TInput2> > >(0, new EqualityComparer <TKey>());
                }
                using (RegionContext regContext = RegionContext.Create(actorRegion))
                {
                    vals.Add(message.time, dictKeyPair);
                    dictRegions.Add(message.time, dictRegion);
                }
            }
            Dictionary <TKey, PairNonCloneable <RegionLinkedList <TInput1>, RegionLinkedList <TInput2> > > dictKeys =
                vals[message.time];

            dictRegion = dictRegions[message.time];

            PairNonCloneable <RegionLinkedList <TInput1>, RegionLinkedList <TInput2> > currentEntry;
            TInput2 curInput;

            using (RegionContext regContext = RegionContext.Create(dictRegion))
            {
                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.
                    // curInput = (TInput2)message.payload[i].Clone();
                    curInput = (TInput2)message.payload[i];
                    var key = keySelector2(curInput);
                    if (!dictKeys.TryGetValue(key, out currentEntry))
                    {
                        currentEntry = new PairNonCloneable <RegionLinkedList <TInput1>, RegionLinkedList <TInput2> >(
                            new RegionLinkedList <TInput1>(), new RegionLinkedList <TInput2>());
                        dictKeys.Add(key, currentEntry);
                    }
                    currentEntry.Second.InsertFirst(curInput);

//          using (RegionContext context = RegionContext.Create(outputRegion))
                    {
                        for (Node <TInput1> cur = currentEntry.First.Head;
                             cur != default(Node <TInput1>); cur = cur.Next)
                        {
                            output.set(outputOffset, resSelector(cur.Data, curInput));
                            outputOffset++;
                        }
                    }
                }
            }
            // The region will be freed.
            output.send(outputRegion);
        }