none
parallel version of DataView.FindRow ? RRS feed

  • Question

  • does DataView.FindRow have a parallel version? how to exec plinq in an existing DataView?
    Wednesday, December 18, 2013 11:19 AM

Answers

  • "But this FindRow method is not parallel."

    And what do you think you'll gain if you make it parallel? Those DataView indexes are red black trees, that means that if an index is used the search is performed in O(log2 n) time. That means that for 1 million records you need something like 20 comparisons to find the record. There's nothing worth parallelizing in this case.

    And to answer your question, it's not possible to use parallelism here because the index is used internally by the data view and you can't alter the way it is searched.

    • Marked as answer by Dr. Vader Sunday, December 22, 2013 12:57 PM
    Saturday, December 21, 2013 7:03 AM
    Moderator

All replies

  • Hi Vader,

    PLINQ implements the full set of LINQ standard query operators as extension methods for the System.Linq namespace. See the following link for details. http://msdn.microsoft.com/en-us/library/dd460688(v=vs.110).aspx.

    PS: DataView does not support LINQ, you should change it to IQueryable first.

    You can convert the search source using AsParallel method, but please be careful when you are using PLINQ. I found if the computation is simple and non-expensive, it is better to use LINQ than PLINQ. Please see the code blow.

    static void Main(string[] args)

            {

                System.Diagnostics.Stopwatch oTime = new System.Diagnostics.Stopwatch();

                int day  =DateTime.Now.Day;

                int month = DateTime.Now.Month;

                int year = DateTime.Now.Year;

                var context = new ConsoleApplication5.SupportEfficiencyTestEntities();

                //take 10000 records for test

                var datas = (from thread in context.Threads

                             select new Test() { Title = thread.Title, Time = thread.CreateTime, Lockedby = thread.Lockedby }).Take(10000).ToList();

              

                //test common Linq

                oTime.Start();

                var search1 = datas.Where(w => w.Title.StartsWith("h")).ToList();

                oTime.Stop();

                Console.WriteLine("LINQ use {0} time to take {1} records",oTime.Elapsed.Ticks,search1.Count());

                oTime.Reset();

                //test PLinq

                oTime.Start();

                var search2 = datas.AsParallel<Test>().Where(w => w.Title.StartsWith("h")).ToList();

                oTime.Stop();

                Console.WriteLine("PLINQ use {0} time to take {1} records", oTime.Elapsed.Ticks, search2.Count());

                Console.Read();

            }

    The result show:

    LINQ use 49849 time to take 149 records.

    PLINQ use 494677 time to take 149 records.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, December 19, 2013 6:03 AM
    Moderator
  • I know basic plinq query, but this question is about DataView, indexing and parallel query:

    When you create a DataView from a DataTable, the orderby fields are indexed so that DataView.FindRow method is speeded up. But this FindRow method is not parallel. The question is: How to query a DataTable using indexing and parallel at the same time?


    • Edited by Dr. Vader Saturday, December 21, 2013 5:17 AM
    Saturday, December 21, 2013 5:16 AM
  • "But this FindRow method is not parallel."

    And what do you think you'll gain if you make it parallel? Those DataView indexes are red black trees, that means that if an index is used the search is performed in O(log2 n) time. That means that for 1 million records you need something like 20 comparisons to find the record. There's nothing worth parallelizing in this case.

    And to answer your question, it's not possible to use parallelism here because the index is used internally by the data view and you can't alter the way it is searched.

    • Marked as answer by Dr. Vader Sunday, December 22, 2013 12:57 PM
    Saturday, December 21, 2013 7:03 AM
    Moderator
  • So quick enough it is, that why it didn't come in parallel.
    Sunday, December 22, 2013 12:58 PM