Click here to Skip to main content
       

C#

 
AnswerRe: collections generic with wcf PinmemberSledgeHammer0119-Jan-13 13:03 
GeneralRe: collections generic with wcf Pinmemberyonim12319-Jan-13 13:20 
QuestionCannot Access the form _ Cross-thread operation Pinmembermohammadkaab19-Jan-13 9:50 
AnswerRe: Cannot Access the form _ Cross-thread operation Pinmemberjibesh19-Jan-13 21:29 
AnswerRe: Cannot Access the form _ Cross-thread operation Pinmemberpt140120-Jan-13 22:13 
GeneralRe: Cannot Access the form _ Cross-thread operation Pinmembermohammadkaab21-Jan-13 20:26 
Questionwcf p2p file transfering over internet Pinmembervab26108519-Jan-13 2:03 
QuestionWorking with tab escape charecter PinmemberMc_Topaz19-Jan-13 1:49 
AnswerRe: Working with tab escape charecter PinmvpAbhinav S19-Jan-13 2:38 
GeneralRe: Working with tab escape charecter PinmemberMc_Topaz19-Jan-13 3:22 
QuestionDesign-Time Error in the Windows Forms Designer [modified] Pinmember_q12_18-Jan-13 4:25 
AnswerRe: Design-Time Error in the Windows Forms Designer PinmvpEddy Vluggen18-Jan-13 5:02 
AnswerRe: Design-Time Error in the Windows Forms Designer PinmemberAlan N18-Jan-13 5:42 
QuestionParalel QuickSort with 2 threads running at the same spped [modified] PinmemberGeorge Nistor18-Jan-13 0:51 
Hi,
 
I made a small program which sorts a Vector of 100000 ints.
I use a quicksort , not the recursive one.
With the single thread version I takes about 22s to complete.
 
-now the problem and the question:
I have written a second version which
1. first make a partitioning
2. start an independent thread on eatch subpartition = 2Threads
So the sorting continues on 2 separate threads with no locks or anythig to block;
 
I got almost the same time when running.
Why happens to run in same interval of time.
Will Windows7 be very smart to optimize the code to run on multiple cores even if it is a single thread?
I have a x6 Cpu.
 
here is the sample code (test code)
class VectorSafeConcurency
    {
        int[] V;
        const int sizeV = 100000;
        //Stack<int> numbers = new Stack<int>();

        void push2(Stack<int> s, int a, int b)
        {
            s.Push(b);
            s.Push(a);
        }
 
        public VectorSafeConcurency()
        {
            V= new int[sizeV];
 
            int value= sizeV;
 
            for (int i = 0; i < sizeV; ++i)
                V[i] = value--;
        }
 
        void exchange(ref int x, ref int y)
        {
            int temp= x; 
            x= y;
            y= temp;
        }
 
        int partition(int[] A, int l, int r)
        {
            int i = l - 1;
            int j = r;
            int v= A[r];
 
            for(;;)
            {
                while(A[++i] <v);
                while (v < A[--j]) if (j == l) break;
                if (i >= j) break;
                exchange(ref A[i], ref A[j]);
            }
            exchange(ref A[i], ref A[r]);
            return i;
        }
 
        struct ThData
        {
            public int[] A;
            public int l;
            public int r;
 
            public ThData(int []a, int i, int j)
            {
                A = a; l = i; r = j;
            }
        }
 

        void thWorkerParititoner(object data)
        {
            int[] A = ((ThData)data).A;
            int l = ((ThData)data).l;
            int r = ((ThData)data).r;
 
            quicksort(A, l, r);
        }
 

        void StartQuicksort(int[] A, int l, int r)
        {
            if (r <= l) return;
            int i = partition(A, l, r);
 
            Thread t1 = new Thread(thWorkerParititoner);
            t1.Start(new ThData (A, l, i-1));
 
            Thread t2 = new Thread(thWorkerParititoner);
            t2.Start(new ThData(A, i+1, r));
            //start th 1
            //start th2
        }
 
        void quicksort(int[] A, int l, int r)
        {
            Stack<int> Indexes = new Stack<int>();
            push2(Indexes, l, r);
 
            while (Indexes.Count > 0)
            {
                l = Indexes.Pop(); r = Indexes.Pop();
 
                if (r <= l) continue;
                int i = partition(V, l, r);
 
                push2(Indexes, l, i - 1);
                push2(Indexes, i + 1, r);
            }
        }
 
        public void StartSort()
        {
            quicksort(V, 0, V.Length - 1);
 
            int d = 1;
        }
    }


modified 18-Jan-13 6:59am.

AnswerRe: Paralel QuickSort with 2 threads running at the same spped PinmvpDave Kreskowiak18-Jan-13 4:20 
GeneralRe: Paralel QuickSort with 2 threads running at the same spped [modified] PinmemberGeorge Nistor18-Jan-13 4:41 
GeneralRe: Paralel QuickSort with 2 threads running at the same spped PinmvpDave Kreskowiak18-Jan-13 6:25 
AnswerRe: Paralel QuickSort with 2 threads running at the same spped PinmemberAlan Balkany18-Jan-13 5:12 
GeneralRe: Paralel QuickSort with 2 threads running at the same spped PinmemberGeorge Nistor18-Jan-13 5:31 
GeneralRe: Paralel QuickSort with 2 threads running at the same spped PinmvpDave Kreskowiak18-Jan-13 6:26 
GeneralRe: Paralel QuickSort with 2 threads running at the same spped PinmemberGeorge Nistor18-Jan-13 6:53 
GeneralRe: Paralel QuickSort with 2 threads running at the same spped PinmvpDave Kreskowiak18-Jan-13 7:31 
GeneralRe: Paralel QuickSort with 2 threads running at the same spped [modified] PinmemberGeorge Nistor18-Jan-13 7:38 
GeneralRe: Paralel QuickSort with 2 threads running at the same spped PinmemberGeorge Nistor18-Jan-13 22:49 
GeneralRe: Paralel QuickSort with 2 threads running at the same spped PinmvpDave Kreskowiak19-Jan-13 3:27 
QuestionDataSet to Dictionary Join? PinmemberRickSharp17-Jan-13 12:25 
GeneralRe: DataSet to Dictionary Join? PinmemberPIEBALDconsult17-Jan-13 12:34 
GeneralRe: DataSet to Dictionary Join? PinmemberRickSharp17-Jan-13 12:51 
GeneralRe: DataSet to Dictionary Join? PinmemberPIEBALDconsult17-Jan-13 13:03 
GeneralRe: DataSet to Dictionary Join? PinmemberRickSharp17-Jan-13 13:13 
AnswerRe: DataSet to Dictionary Join? PinmemberHuorSwords17-Jan-13 21:18 
GeneralRe: DataSet to Dictionary Join? PinmemberRickSharp18-Jan-13 7:02 
QuestionLinking files to a project PinmemberTheGermoz17-Jan-13 8:43 
GeneralRe: Linking files to a project PinmemberPIEBALDconsult17-Jan-13 9:12 
GeneralRe: Linking files to a project PinmemberTheGermoz17-Jan-13 9:44 
QuestionError : System.DllNotFoundExpection Pinmembermohammadkaab17-Jan-13 6:37 
AnswerRe: Error : System.DllNotFoundExpection Pinmemberjibesh17-Jan-13 7:14 
GeneralRe: Error : System.DllNotFoundExpection Pinmembermohammadkaab17-Jan-13 7:48 
GeneralRe: Error : System.DllNotFoundExpection Pinmemberjibesh17-Jan-13 7:53 
Questioncalling a C# function with jquery ajax PinmemberHector Ubiera17-Jan-13 4:14 
AnswerRe: calling a C# function with jquery ajax PinprotectorPete O'Hanlon17-Jan-13 6:30 
GeneralRe: calling a C# function with jquery ajax PinmemberHector Ubiera17-Jan-13 8:05 
QuestionStatic & Dynamic Polymorphism : distinguished in C# PinmemberMember 883921917-Jan-13 3:29 
AnswerRe: Static & Dynamic Polymorphism : distinguished in C# PinprotectorPete O'Hanlon17-Jan-13 3:46 
QuestionComposition implementation in C# PinmemberMember 883921917-Jan-13 3:23 
QuestionRe: Composition implementation in C# PinmvpEddy Vluggen17-Jan-13 3:30 
QuestionImplementation of Encapsulation & inheritance in c# PinmemberMember 883921917-Jan-13 2:55 
AnswerRe: Implementation of Encapsulation & inheritance in c# PinprotectorPete O'Hanlon17-Jan-13 3:02 
Questionhow to send sms in windows application? Pinmemberkiran murkal16-Jan-13 23:57 
AnswerRe: how to send sms in windows application? PinprotectorPete O'Hanlon17-Jan-13 0:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 20 Apr 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid