Parallel programing
<p>I have a lot of sortedlists&lt;> in my program. I run my program for large number of repeats. In each repeat a lot of data add to the sorted lists and data from previous repeat also add to current list through loops.At first, number of data is small then the program is fast, but gradually amount of data increase and performance decrease. I want to increase the speed of my program therefore I decided to use Parallel task (each list as a task to add data to lists concurrently) and Parallel loop (to copy data from previous to current list) as well as concurrent dictionary (instead of sorted list). Not only did performance not increase but also it decreased radically. Add object to concurrent dictionary is very slow.
Is it worthwhile to use parallel programming? If yes, Could you please give me a clue?  </p>

<p>Sample codes...</p>

<pre><code>class Segment&lt;T, X&gt;
    {
        public ChrSegment()
        {
        }

        public SortedList&lt;T, X&gt; Zero { get; set; }
        public SortedList&lt;T, X&gt; One { get; set; }
        public SortedList&lt;T, X&gt; Two { get; set; }
        public SortedList&lt;T, X&gt; Three { get; set; }
        public SortedList&lt;T, X&gt; Four { get; set; }
        public SortedList&lt;T, X&gt; Five { get; set; }
        public SortedList&lt;T, X&gt; Six { get; set; }
        public SortedList&lt;T, X&gt; Seven { get; set; }
        public SortedList&lt;T, X&gt; Eight { get; set; }
        public SortedList&lt;T, X&gt; Nine { get; set; }
}

        static void Main(string[] args)
        {
            Segment.Zero = Loop(tmpZero); \\tmp is sorted list from previous repeat
            Segment.One = Loop(tmpOne);
            Segment.Two = Loop(tmpTwo);
            Segment.Three = Loop(tmpThree);
            Segment.Four = Loop(tmpFour);
            Segment.Five = Loop(tmpFive);
            Segment.Six = Loop(tmpSix);
            Segment.Seven = Loop(tmpSeven);
            Segment.Eight = Loop(tmpEight);
            Segment.Nine = GetPreGroup(NewtmpNine) \\Newtmp sorted list from current repeat
        }

        protected static SortedList&lt;int, ushort&gt; Loop(SortedList&lt;int, ushort&gt; tmp)
        {
            var Return = new SortedList&lt;int, ushort&gt;();
            foreach (var item in tmp)
            {
                Return.Add(item.Key, item.Value);
            }
            return Return;
        }

        protected static SortedList&lt;int, ushort&gt; GetPreGroup(SortedList&lt;int, ushort&gt; Newtmp)
        {
            var Return = new SortedList&lt;int, ushort&gt;();

            for (int l = 0; l &lt; tmp.Count; l++)
            {
              Return.Add(tmp.Keys[l], tmp[tmp.Keys[l]]);
            }

            return Return;
        }

------------------------------------------------------------------Parallel


class Segment&lt;T, X&gt;
    {
        public ChrSegment()
        {
        }

        public ConcurrentDictionary&lt;T, X&gt; Zero { get; set; }
        public ConcurrentDictionary&lt;T, X&gt; One { get; set; }
        public ConcurrentDictionary&lt;T, X&gt; Two { get; set; }
        public ConcurrentDictionary&lt;T, X&gt; Three { get; set; }
        public ConcurrentDictionary&lt;T, X&gt; Four { get; set; }
        public ConcurrentDictionary&lt;T, X&gt; Five { get; set; }
        public ConcurrentDictionary&lt;T, X&gt; Six { get; set; }
        public ConcurrentDictionary&lt;T, X&gt; Seven { get; set; }
        public ConcurrentDictionary&lt;T, X&gt; Eight { get; set; }
        public ConcurrentDictionary&lt;T, X&gt; Nine { get; set; }
}

        static void Main(string[] args)
        {
           var tasks = new Task[10]
           {
            Task.Factory.StartNew(()=&gt;Segment.Zero = Loop(NewtmpZero),
            Task.Factory.StartNew(()=&gt;Segment.One = Loop(tmpOne)),
            Task.Factory.StartNew(()=&gt;Segment.Two = Loop(tmpTwo)),
            Task.Factory.StartNew(()=&gt;Segment.Three = Loop(tmpThree)),
            Task.Factory.StartNew(()=&gt;Segment.Four = Loop(tmpFour)),
            Task.Factory.StartNew(()=&gt;Segment.Five = Loop(tmpFive)),
            Task.Factory.StartNew(()=&gt;Segment.Six = Loop(tmpSix)),
            Task.Factory.StartNew(()=&gt;Segment.Seven = Loop(tmpSeven)),
            Task.Factory.StartNew(()=&gt;Segment.Eight = Loop(tmpEight)),
            Task.Factory.StartNew(()=&gt;Segment.Nine = GetPreGroup(tmpNine)
            };
            Task.WaitAll(tasks);
}

       protected static ConcurrentDictionary&lt;int, ushort&gt; Loop(SortedList&lt;int, ushort&gt; tmp)
        {
            var Return= new ConcurrentDictionary&lt;int, ushort&gt;();
            Parallel.ForEach(tmp, item =&gt;
            {
                Return.TryAdd(item.Key, item.Value);
            });
            return Return;
        }



       protected static ConcurrentDictionary&lt;int, ushort&gt; GetPreGroup(SortedList&lt;int, ushort&gt; Newtmp)
        {
            var Return = new ConcurrentDictionary&lt;int, ushort&gt;();

            Parallel.For(0, Newtmp.Count, l =&gt;
            {
               Return.TryAdd(tmpMutation.Keys[l], tmp[tmp.Keys[l]]);
            });

            return Return;
        }
</code></pre>
