0

When I compile the following file with f2c, it fails with a noninformative syntax error message

f2c  < ../../libcruft/blas-xtra/ddot3.f >ddot3.c
   ddot3:
Error on line 37: syntax error

gfortran compiles it without any error. Do you have an idea what can cause it? Do you know of any fortran compiler that would be strict as f2c and have good error messages?

The file in question:

c Copyright (C) 2009-2012  VZLU Prague, a.s., Czech Republic
c
c Author: Jaroslav Hajek <highegg@gmail.com>
c
c This file is part of Octave.
c
c Octave is free software; you can redistribute it and/or modify
c it under the terms of the GNU General Public License as published by
c the Free Software Foundation; either version 3 of the License, or
c (at your option) any later version.
c
c This program is distributed in the hope that it will be useful,
c but WITHOUT ANY WARRANTY; without even the implied warranty of
c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c GNU General Public License for more details.
c
c You should have received a copy of the GNU General Public License
c along with this software; see the file COPYING.  If not, see
c <http://www.gnu.org/licenses/>.
c
      subroutine ddot3(m,n,k,a,b,c)
c purpose:      a 3-dimensional dot product.
c               c = sum (a .* b, 2), where a and b are 3d arrays.
c arguments:
c m,n,k (in)    the dimensions of a and b
c a,b (in)      double prec. input arrays of size (m,k,n)
c c (out)       double prec. output array, size (m,n)
      integer m,n,k,i,j,l
      double precision a(m,k,n),b(m,k,n)
      double precision c(m,n)

      double precision ddot
      external ddot


c quick return if possible.
      if (m <= 0 .or. n <= 0) return

      if (m == 1) then
c the column-major case.
        do j = 1,n
          c(1,j) = ddot(k,a(1,1,j),1,b(1,1,j),1)
        end do
      else
c We prefer performance here, because that's what we generally
c do by default in reduction functions. Besides, the accuracy
c of xDOT is questionable. Hence, do a cache-aligned nested loop.
        do j = 1,n
          do i = 1,m
            c(i,j) = 0d0
          end do
          do l = 1,k
            do i = 1,m
              c(i,j) = c(i,j) + a(i,l,j)*b(i,l,j)
            end do
          end do
        end do
      end if

      end subroutine
user7610
  • 25,267
  • 15
  • 124
  • 150
  • Overlaps somewhat with http://stackoverflow.com/questions/17004270/strict-fortran77-compiler-or-gfortran-compiler-flag – user7610 Nov 25 '13 at 15:31
  • Fortran is such a lovely, elegant language… no? – Fiddling Bits Nov 25 '13 at 15:47
  • Actually ... yes, but must know more than just some version obsolete for more than 20 year. – Vladimir F Героям слава Nov 25 '13 at 15:55
  • I only used Fortran03 before. For about one day. It was quite similar to Matlab; nothing like this. At one seminar at school (Introduction to use of clusters supercomputers in chemistry) we had a lab where we had to write parallel matrix multiplication in Fortran, with OpenMP. One of their's 64 core computers for quantum simulations was just out of maintainance (this one http://lcc.ncbr.muni.cz/whitezone/root/hardware.html#sokar) and we were allowed to test the programs on it. Nice way to see Amdahl's law in action ;-) and also how slow we were compared to the library versions. – user7610 Nov 25 '13 at 18:28
  • This doesn't mean you cannot write efficient code in modern Fortran (or modern C++, or whatever). You can also write quite inefficient code in Fortran 77. Also, for many of us the developer's (ours) time is more precious, than the machine time. And even if you use just Fortran 95, it is so much better. – Vladimir F Героям слава Nov 25 '13 at 19:26
  • @VladimirF ;D This means that a three-nested-for-loops (or do loops, if you prefer) implementation of the formula c(i,j) += a(i,k)*b(k,j) is much slower than what is already available in a library. – user7610 Nov 25 '13 at 19:55
  • But that is very well known. – Vladimir F Героям слава Nov 25 '13 at 21:42

1 Answers1

2

I believe that f2c expects to read FORTRAN77 and the line

if (m <= 0 .or. n <= 0) return

uses a token (ie <=) that was introduced in Fortran 90. Try changing the line to

if (m .le. 0 .or. n .le. 0) return

I expect that if this fixes the problem f2c will next complain about == which is also a Fortran 90 introduction.

Do not read on if you are a fan of f2c.

As for Do you know of any fortran compiler that would be strict as f2c and have good error messages? you're joking right ? f2c is an outdated pile of insert your favourite term of moderate-to-severe disapproval here which was probably a bad idea back in 1990 when it was first published. Now that interoperability between Fortran and C is (a) standardised and (b) easier than ever before I see no good reason for using it.

High Performance Mark
  • 77,191
  • 7
  • 105
  • 161
  • My reason for using f2c is that I want to compile Octave for use with Google's Native client (and then possibly also asm.js). I found an old blog (2009) that talked about using f2c, so I decided to give it a try. Other possibilities that I was considering were the highly experimental https://github.com/hyp/flang (it is IMHO approx. on par with f2c regarding features). f2c was the first tool that I came across. It compiled about 50 fortran files before it died on this one, so maybe there is just a few equal signs that I need to fix. Or I can wait for flang to get more mature. – user7610 Nov 25 '13 at 18:10
  • Flang is extremely immature. Alas, they are still in the process of developing module support! There are so many good compilers you can use, some of them being free. Gfortran, G95, Open64 on Linux and Solaris even Solaris Studio is at no cost. – Vladimir F Героям слава Nov 25 '13 at 19:29
  • Thanks for your answer. It was wrong, but it made me to look at it again and solve it. f2c takes <=, == all right. The error is caused by the `end procedure` line. Canging it to `end` fixes it. @VladimirF No, I cannot. The Portable Client (PNaCl, the LLVM bytecode thing) makes it either flang or source code translation. – user7610 Nov 25 '13 at 20:04
  • If you really need C source, why not write in C from the beginning?? Otherwise the binaries produced by any of the compilers can be called from C without any problem. Maybe we could talk about this a bit on the Topical problems in FM conference if you join (normally do). – Vladimir F Героям слава Nov 25 '13 at 21:46
  • My mistake. I mean `end subroutine`, changing it to just `end` – user7610 Nov 26 '13 at 08:13
  • @VladimirF What is FM conference? Where do I find it. – user7610 Dec 03 '13 at 16:29