Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Why C is much slower than Fortran
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Vincent Ma  
View profile  
 More options Apr 12 1999, 3:00 am
Newsgroups: comp.lang.c++, comp.lang.fortran, comp.compiler
From: Vincent Ma <vinm...@hotmail.com>
Date: 1999/04/12
Subject: Re: Why C is much slower than Fortran
Dear friends,

Thanks for the reply. Here are more detailed information:

-------------------------------------------------------------
#include <stdio.h>

void main()
{
float  E[36][21][52];
float  H1[36][21][52];
float  H2[36][21][52];

 short int    ID[43][31][52];
 float  A1[10];
 float  A2[10];
 float  A3[10];

    int    i,j,k,nlp,nmax;
    int    imax, jmax, kmax;

/* ============= set parameters ============== */

        imax           =   35;
        jmax           =   20;
        kmax           =   50;

/* ============== input nmax ================= */

        nmax = 1000;

/* -----------  set initial conditions ---------- */

 for(k = 1; k <= kmax-1; k++)
 {
  for(j = 1; j <= jmax-1; j++)
  {
   for(i = 1; i <= imax-1; i++)
   {

    ID[i][j][k] = 0;
    E[i][j][k] = 4.;
    H1[i][j][k] = 5.;
    H2[i][j][k] = 6.;
    A1[0] = 0.;
    A2[0] = 2.;
    A3[0] = 3.;
           }
  }
 }

/* ############################## */

        for (nlp = 0; nlp <= nmax; nlp++)
  {
            for(i = 0; i <= imax-1; i++)
   {
               for(j = 1; j <= jmax-1; j++)
      {
                  for(k = 1; k <= kmax-1; k++)
      {
                     E[i][j][k] = A1[ID[i][j][k]]*E[i][j][k]  + A2[ID[i][j][k]]
* (H1[i][j][k] - H1[i][j-1][k] + A3[ID[i][j][k]] * (H2[i][j][k] - H2[i][j][k-1]
);
                  }
               }
            }

  }

        return;

}

--------------------------------------------------------------------------- --------------------------------------------

Fortran test code is same. I ran both on Pentium 133 with 64 meg RAM with MS
Powerstation and Visual C++ 5 with full optimization on. The execution time are

Fortran -- 11 sec (i loop innermost)
C -- 101 sec (i loop innermost)
C -- 62 sec   (k innermost).

The difference is still a lot (6 times). I've tried many variations, it seems no
matter what I did, C is always slower. My previous experience on workstation
told me the same story that fortran is much faster than C (at least for this
scientific computing case).


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.