Optimization of gfortran for execution speed

Feng Wang wf_cs@yahoo.com
Wed Nov 2 10:11:00 GMT 2005


--- Richard Henderson <rth@twiddle.net> wrote:

> On Wed, Nov 02, 2005 at 03:11:31PM +0800, Feng Wang wrote:
> > > More than that: if the array is SAVEd (or other Fortran words that
> > > mean it's in static storage), the descriptor can be static as well,
> > > and reside in read-only memory.
> > > 
> > 
> > But the initialization still remains in the loop, especially invoking
> > malloc() and free() functions, which are the main cost.
> 
> Huh?  The initialization would not be in the loop.  It would be in
> the compiler, and not in the program at all.
> 

The LOOP I referenced is loop in the user program, that is what Paul T used for
illustrate this problem. Sorry not to make it clear.  Please see:

>From http://gcc.gnu.org/ml/fortran/2005-10/msg00443.html

  if (i <= 10000000)
    {
      while (1)
        {
          {
            logical4 D.573;

            {
              struct array1_real4 parm.1;
              struct array1_real4 parm.0;

              parm.0.dtype = 281;
              parm.0.dim[0].lbound = 1;
              parm.0.dim[0].ubound = 12;
              parm.0.dim[0].stride = 1;
              parm.0.data = (void *) (real4[0:] *) &x[0];
              parm.0.offset = 0;
              parm.1.dtype = 281;
              parm.1.dim[0].lbound = 1;
              parm.1.dim[0].ubound = 12;
              parm.1.dim[0].stride = 1;
              parm.1.data = (void *) (real4[0:] *) &y[0];
              parm.1.offset = 0;
              z = _gfortran_dot_product_r4 (&parm.0, &parm.1);
            }
            L.1:;
            D.573 = i == 10000000;
            i = i + 1;
            if (D.573) goto L.2; else (void) 0;
          }
        }
    }

And http://gcc.gnu.org/ml/fortran/2005-10/msg00464.html

  if (j <= 4)
    {
      while (1)
        {
          {
            logical4 D.575;

            {
              void * D.571;
              int4 D.570;
              struct array1_int4 atmp.0; /*   <= Note the temporary.  */

              atmp.0.dtype = 265;
              atmp.0.dim[0].stride = 1;
              atmp.0.dim[0].lbound = 0;
              atmp.0.dim[0].ubound = n - 1;
              D.570 = NON_LVALUE_EXPR <n>;
              D.571 = _gfortran_internal_malloc (D.570 * 4);
              atmp.0.data = D.571;
              atmp.0.offset = 0;
              {
                int4 S.1;

                S.1 = 0;
                while (1)
                  {
                    if (S.1 > n - 1) goto L.3; else (void) 0;
                    (*(int4[0:] *) atmp.0.data)[NON_LVALUE_EXPR <S.1>] =
i[NON_LVALUE_EXPR <S.1> + 1];
                    S.1 = S.1 + 1;
                  }
                L.3:;
                S.1 = 0;
                while (1)
                  {
                    if (S.1 > n - 1) goto L.4; else (void) 0;
                    i[NON_LVALUE_EXPR <S.1>] = (*(int4[0:] *)
atmp.0.data)[NON_LVALUE_EXPR <S.1>];
                    S.1 = S.1 + 1;
                  }
                L.4:;
              }
              _gfortran_internal_free (atmp.0.data);
            }
            L.1:;
            D.575 = j == 4;
            j = j + 1;
            if (D.575) goto L.2; else (void) 0;
          }
        }


Even we put the temporary variable declaration at the beginning of the
function, its initialization and memory related stuff still remain the loop.
Ideally, we should move them out of the loop.



Best Regards,
Feng Wang

--
Creative Compiler Research Group,
National University of Defense Technology, China.


	
	
		
__________________________________ 
Do you Yahoo!? 
New and Improved Yahoo! Mail - 1GB free storage! 
http://sg.whatsnew.mail.yahoo.com



More information about the Fortran mailing list