public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jb at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/29549] matmul slow for complex matrices
Date: Sat, 04 Nov 2006 21:24:00 -0000	[thread overview]
Message-ID: <20061104212424.31244.qmail@sourceware.org> (raw)
In-Reply-To: <bug-29549-1719@http.gcc.gnu.org/bugzilla/>



------- Comment #3 from jb at gcc dot gnu dot org  2006-11-04 21:24 -------
Well, redoing the C benchmark above to use 1d arrays and manual index
calculations, the results are now essentially the same as for the Fortran
version. And a commercial compiler produces about the same results for the
Fortran version as gfortran, which means the reason for our poor complex matmul
performance lies elsewhere.

#include <stdio.h>
#include <stdlib.h>
#include <complex.h>
#include <sys/time.h>
#include <time.h>

int main(void)
{
  int n = 300;
  complex float *a, *b, *c;
  int i, j, k, tc;
  a = malloc (n*n * sizeof (*a));
  b = malloc (n*n * sizeof (*b));
  c = malloc (n*n * sizeof (*c));
  struct timeval tv, tv2;
  float res;
  FILE *fp;

  tc = 0;
  for (i = 0; i < n*n; i++)
    {
      a[i] = i*10.0 + 100.0*I;
      b[i] = 1.0 + 42.0*I;
      c[i] = 0.0 + 0.0*I;
    }

  gettimeofday (&tv, NULL);

  for (i = 0; i < n; i++)
    {
      for (j = 0; j < n; j++)
        {
          c[i*n + j] = 0.0 + 0.0*I;
          for (k = 0; k < n; k++)
            {
              c[i*n + j] = c[i*n + j] + a[i*n + k] * b[k*n + j];
              tc++;
            }
        }
    }
  gettimeofday (&tv2, NULL);
  res = tv2.tv_sec - tv.tv_sec + (tv2.tv_usec - tv.tv_usec) / 1000000.0;
  printf ("gemm time: %f\n", res);
  fp = fopen ("c-matrix", "w");
  for (i = 0; i < n; i++)
    {
      for (j = 0; j<n; j++)
        {
          fprintf (fp, "%f ", c[i*n + j]);
        }
      fprintf (fp, "\n");
    }
  fclose (fp);
  printf ("trip count: %i\n", tc);
}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29549


  parent reply	other threads:[~2006-11-04 21:24 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-22 15:58 [Bug fortran/29549] New: " tobias dot burnus at physik dot fu-berlin dot de
2006-11-04 14:15 ` [Bug fortran/29549] " jb at gcc dot gnu dot org
2006-11-04 20:34 ` jb at gcc dot gnu dot org
2006-11-04 21:24 ` jb at gcc dot gnu dot org [this message]
2006-11-04 22:17 ` jb at gcc dot gnu dot org
2008-02-10 19:20 ` jb at gcc dot gnu dot org
2008-02-10 22:48 ` tkoenig at gcc dot gnu dot org
2008-02-16 18:50 ` fxcoudert at gcc dot gnu dot org
2008-02-16 19:01 ` fxcoudert at gcc dot gnu dot org
2008-02-16 21:59 ` rguenth at gcc dot gnu dot org
2008-02-16 22:33 ` jb at gcc dot gnu dot org
2008-02-19 19:34 ` jb at gcc dot gnu dot org
2008-02-25 19:22 ` jb at gcc dot gnu dot org
2008-02-25 19:28 ` jb at gcc dot gnu dot org
2008-02-26 21:15 ` jb at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20061104212424.31244.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).