CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2010
    Posts
    2

    cual core, quad core, i3,i5,i7 optimized and 100% cpu's

    Hello,

    I would like a sample source code for create a program where use 100% of all CPU's/cores on dual/quad core or new I3,I5,I7.

    For example: i have a simple program for calculating a numbers, but, when i start only have usage 50% of my dual core, the other is 0% usage. I would like use the two cores at time.

    thanks all.

  2. #2
    Join Date
    Jul 2009
    Location
    India
    Posts
    835

    Re: cual core, quad core, i3,i5,i7 optimized and 100% cpu's

    can use a infinite for loop...

    Code:
    for (;;)
    {
      for (;;) 
      {
        //some stuffs.. like:: FindWindow(). Finding a window that is not created yet. so the loop continues.
        //a break statements if you want to terminate infinite loop.
      }
    }
    Last edited by hypheni; July 26th, 2010 at 05:36 AM.

  3. #3
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: cual core, quad core, i3,i5,i7 optimized and 100% cpu's

    Quote Originally Posted by hypheni View Post
    can use a infinite for loop...
    No, that won't work. When executed on a dual-core machine, the "infinite loop" code would still show only 50% utilization.

    To the OP, you need to understand threading. To use multiple cores simultaneously, your code needs to start multiple threads.

    The "infinite loop" code above is still only singly-threaded, and thus will not use all cores.

  4. #4
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: cual core, quad core, i3,i5,i7 optimized and 100% cpu's

    To use multiple cores simultaneously, your code needs to start multiple threads.
    Multiple child threads belonging to a single task doesn't always mean multiple cores are used... this all depends on the OS and the optimization used by the OS and which instructions are used. So, which OS is used for this question ?

  5. #5
    Join Date
    Jul 2010
    Posts
    2

    Re: cual core, quad core, i3,i5,i7 optimized and 100% cpu's

    SO: LINUX or Windows 7 64

    I need only a example code for use 2 or 4 core together=100% cpu!!!

    thanks all,

  6. #6
    Join Date
    Jul 2009
    Location
    India
    Posts
    835

    Re: cual core, quad core, i3,i5,i7 optimized and 100% cpu's

    See. Some days back I used a for(; with some statements inside on my dual core win xp machine and it was almost utilizing 90-100% of cpus. Multiple threading will be a good choice but I think putting preferred statements in nested for(; also utilize 100% of cpu. It depends on what you are putting inside the loop.
    Last edited by hypheni; July 27th, 2010 at 12:43 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured