Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: How can this program run faster on my Atom than on my i7?

  1. #1
    Join Date
    Jun 2007
    Location
    Minneapolis, MN
    Beans
    749
    Distro
    Ubuntu 12.04 Precise Pangolin

    How can this program run faster on my Atom than on my i7?

    The program is a version of Conway's game of life that I wrote.

    It runs faster on my Atom 330 running Ubuntu 13.10 alpha 64 bit
    than it does on my i7 running Ubuntu 12.04 64 bit..

    The program compiles instantly on each machine.

    I copied the executable compiled on the Atom to the i7 and it ran the same speed as the version compiled on the i7.

    On everything else I have ever run the i7 seems fast and the Atom dog slow.

    How can this be?

    Code:
    
    /*
      Filename: life.c
    
      Conway's game of life
    */
    
    #include <stdio.h>
    #include <stdlib.h>
    
    #define clrscr() printf("\e[1;1H\e[2J")
    
    //                                         1                   2                   3                   4                   5                   6                   7                   8
    //                     0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1
    
    int start[24][82] = { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    		      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    		      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    		      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    		      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    		      {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} };
    
    
    
    int count[24][82];
    
    
    int firstTime = 1;
    
    /*
     The loop function.
    
    /*******************************************************/
    
    void loop(void)
    {
      int i,j;
      long k;
      long waitTime = 50000000;
    
      clrscr();
    
      for(i=1;i<24;i++)      // Display starting point.
      {
        for(j=1;j<81;j++)
        {
          if(start[i][j]==0) printf(" ");  
          else  printf("0");
        }
        printf("\n");
      }
    
      if(firstTime == 1)
      {
        for(k=0;k<waitTime*5;k++);
        firstTime = 0;
      }
      else
      {
        for(k=0;k<waitTime;k++);
      }
    
      for(i=0;i<24;i++)     // Zero counts from previous iteration.
      {
        for(j=0;j<81;j++)
        {
          count[i][j]=0;
        }
      }
    
    /*******************************************************/
    
      for(i=1;i<24;i++)     // Count adjacent live cells.
      {
        for(j=1;j<81;j++)
        {
          if(start[i-1][j-1]==1) count[i][j]++;
          if(start[i-1][j]==1) count[i][j]++;
          if(start[i-1][j+1]==1) count[i][j]++;
    
          if(start[i][j-1]==1) count[i][j]++;
          if(start[i][j+1]==1) count[i][j]++;
    
          if(start[i+1][j-1]==1) count[i][j]++;
          if(start[i+1][j]==1) count[i][j]++;
          if(start[i+1][j+1]==1) count[i][j]++;
        }
      }
    
    /*******************************************************/
    
      for(i=1;i<24;i++)     // Switch on/off cells.
      {
        for(j=1;j<81;j++)
        {
          if (count[i][j]<2) start[i][j]=0;
          if (count[i][j]>3) start[i][j]=0;
          if (count[i][j]==3) start[i][j]=1;
        }
      }
    
    }
    
    
    int main(void)
    {
    
      while(1)
      {
        loop();
      }
    
      return(0);
    }
    Last edited by JRV; August 9th, 2013 at 06:50 AM.
    Moderation in all things; including moderation.

  2. #2
    Join Date
    Jun 2009
    Location
    0:0:0:0:0:0:0:1
    Beans
    3,995
    Distro
    Xubuntu 13.04 Raring Ringtail

    Re: How can this program run faster on my Atom than on my i7?

    are you running 32bit on the i7?
    how many samples did you do on each system?
    how much of a difference are we talking about as a percentage?
    which i7 and which atom

    the power state manager is different on 13.10, so the i7 may be runinng at 800Mhz on the i7 and at the atoms max speed
    Laptop: ASUS A54C-NB91 (Storage: WD3200BEKT + MKNSSDCR60GB-DX); Desktop: Custom Build - Images included
    I frequently edit my post several times when I have the last post
    Putting your Networked Printer's scanner software to shame PHP Scanner Server

  3. #3
    Join Date
    Jun 2007
    Location
    Minneapolis, MN
    Beans
    749
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How can this program run faster on my Atom than on my i7?

    Quote Originally Posted by pqwoerituytrueiwoq View Post
    are you running 32bit on the i7?
    No, it's 64 bit.
    how many samples did you do on each system?
    5 or 6
    how much of a difference are we talking about as a percentage?
    The i7 is ~70% as fast.
    which i7 and which atom
    Atom 330 with Intel 945G chipset at 1600MHz. (1600MHz is max.) Intel D945GCLF2 motherboard.
    I7-920 with Intel X58 chipset - Conky says it's running at 1600MHz. (2600MHz is max.)
    Forcing it to 2600MHZ does not seem to make a difference.
    Last edited by JRV; August 9th, 2013 at 08:04 AM.
    Moderation in all things; including moderation.

  4. #4
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,297
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How can this program run faster on my Atom than on my i7?

    Processors are very complicated beasts. Arguably the most complicated things ever built by man, to the point that it is often said to be a miracle that they work at all. So sometimes, they do weird things, and such performance discrepancies are somewhat common. Unless you want to dig very deep in their insides, it's probably better to not give it too much thought.
    「明後日の夕方には帰ってるからね。」


  5. #5
    Join Date
    Dec 2004
    Location
    Manchester
    Beans
    2,077
    Distro
    Ubuntu Studio 13.04 Raring Ringtail

    Re: How can this program run faster on my Atom than on my i7?

    what command are you using to compile it?

    it looks like the code uses empty loops as delays
    Code:
    for(k=0;k<waitTime;k++);
    the compiler ought to optimise these out, basically optimise it to
    Code:
    k=waitTime
    but maybe you have optimisation disabled on the i7

  6. #6
    Join Date
    Jun 2007
    Location
    Minneapolis, MN
    Beans
    749
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How can this program run faster on my Atom than on my i7?

    Quote Originally Posted by ssam View Post
    what command are you using to compile it?
    Code:
    gcc -o life life.c
    Moderation in all things; including moderation.

  7. #7
    Join Date
    Dec 2004
    Location
    Manchester
    Beans
    2,077
    Distro
    Ubuntu Studio 13.04 Raring Ringtail

    Re: How can this program run faster on my Atom than on my i7?

    try:
    Code:
    gcc -O2 -o life life.c
    or
    Code:
    gcc -O3 -o life life.c
    you might also want to put a
    Code:
    -march=native
    in there so that gcc can take full advantage of the cpu.

    if you actually need delays in there, then you'll have to put a proper time based delay. spinning loops just waste CPU (though sometimes in kernel code spinlocks can be useful).

  8. #8
    Join Date
    Jun 2007
    Location
    Minneapolis, MN
    Beans
    749
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How can this program run faster on my Atom than on my i7?

    Quote Originally Posted by ssam View Post
    if you actually need delays in there, then you'll have to put a proper time based delay.
    Both the -O2 and -O3 options remove the delay and make it too fast.

    How do I write a time based delay of about 1/5 second.
    I've never needed to slow a program down before.

    Except an an Arduino which has a command for it.
    Moderation in all things; including moderation.

  9. #9
    Join Date
    May 2008
    Location
    UK
    Beans
    1,448
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: How can this program run faster on my Atom than on my i7?

    at least fetch the current clock time each loop iteration and check if you have advanced the time. the optimiser wont remove those calls, and therefore wont optimise the loop away - even when you turn on optimisation on.
    Tony - Happy to try to help.
    Unless otherwise stated - all code posted by me is untested. Remember to Mark the Thread as Solved.
    Ubuntu user number # 24044 Projects : TimeWarp - on the fly Backups

  10. #10
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,297
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How can this program run faster on my Atom than on my i7?

    I might be missing something, but why not just use sleep() et al.?
    「明後日の夕方には帰ってるからね。」


Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

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