laredo@csri.toronto.edu (Jim Alain Laredo) (08/01/89)
To those of you that have used any of the Fortran to C translators,
please, tell me what the expected results for this small routine are
SUBROUTINE X(A,M)
INTEGER M
DOUBLE PRECISION A(M,*)
INTEGER I,J
DO 20 I=1,M
DO 10 J=I+1,M
A(I,J) = A(I,J)+1
10 CONTINUE
20 CONTINUE
According to the FOR_C brochure (from COBALT BLUE) the coordinates
of the matrices are inverted to solve the problem of the memory
distribution, Fortran places the matrices column-wise as oppossed to C
that does it row-wise. Therefore a reference in Fortran to A(i,j)
should be translated into C as A[M*j+i].
Also, I would like to know if the translator modifies the loops,
note that in the first loop , DO 20 I=1,M, both values have to be
be decremented, while in the second, DO 10 J=I+1,M, only the absolute
value M, should be decremented to fit into the C matrix definitions.
If the translator is good, I would expect the following code or
at least something similar.
void X(A,M)
int M;
double A[];
{
int i,j;
for(i=0;i<=M-1;i++)
for(j=i+1;j<=M-1;j++)
A[j*M+i] = A[j*M+i]+1;
}
thanks for your help,
Jim Laredo
laredo@csri.toronto.eduralphc@tekcae.CAX.TEK.COM (Ralph Carpenter) (08/02/89)
In response to Jim Laredo's <1989Aug1.105428.18152@jarvis.csri.toronto.edu>
question about FOR_C's translation of a sample subroutine:
subroutine x(a,m)
integer m
double precision a(m,*)
integer i,j
do 20 i=1,m
do 10 j=i+1,m
a(i,j)=a(i,j)+1
10 continue
20 continue
end
According to Jim:
> If the translator is good, I would expect the following code or
>at least something similar.
>
> void X(A,M)
> int M;
> double A[];
> {
> int i,j;
> for(i=0;i<=M-1,i++)
> for(j=i+1;j<=M-1;j++)
> A[j*M+i] = A[j*M+i]=1;
> }
I have a FOR_C DEMO v2.0 demo disk, (files dated 10/15/88, probably a
little out of date by now,) which output the following c code:
/*Translated by FOR_C, v2.0, on 08/01/89 at 18:24:20 */
/*FOR_C Options SET: none */
#include <stdio.h>
#include <math.h>
#include <f_rt.h>
void /*FUNCTION*/ x(a, m)
double *a;
int *m;
{
#define A(I_,J_) (a+(I_)*(*m)+(J_))
int _do0, _do1, i, j;
for( i = 0, _do0 = *m - 1; i <= _do0; i++ ){
for( j = (i+1) + 0, _do1 = *m - 1; j <= _do1; j++ ){
*A(j,i) = *A(j,i) + 1;
}
}
#undef A
} /* end of function */
Ralph Carpenter
Tektronix, Inc.scf@statware.UUCP (Steve Fullerton) (08/04/89)
In article <2992@tekcae.CAX.TEK.COM> ralphc@tekcae.CAX.TEK.COM (Ralph Carpenter) writes: > >In response to Jim Laredo's <1989Aug1.105428.18152@jarvis.csri.toronto.edu> >question about FOR_C's translation of a sample subroutine: > > subroutine x(a,m) > integer m > double precision a(m,*) > integer i,j > do 20 i=1,m > do 10 j=i+1,m > a(i,j)=a(i,j)+1 > 10 continue > 20 continue > end > Here are several FOR_C translations I did on the code using version v2.2 under SCO XENIX. For the first translation, I specified options to disable the creation of temporaries for the DO test parameter and requested optimization of common subexpressions. /*Translated by FOR_C, v2.2, on 08/03/89 at 13:14:57 */ /*FOR_C Options SET: no=d op=a */ #include <stdio.h> #include <math.h> #include <f_rt.h> void /*FUNCTION*/ x(a, m) double *a; int *m; { #define A(I_,J_) (a+(I_)*(*m)+(J_)) int i, i_, j, j_; for( i = 1; i <= *m; i++ ){ i_ = i - 1; for( j = i + 1; j <= *m; j++ ){ j_ = j - 1; *A(j_,i_) += 1; } } #undef A } /* end of function */ This next translation used an addition option to prevent the creation of a reduced DO index variable. /*Translated by FOR_C, v2.2, on 08/03/89 at 13:14:16 */ /*FOR_C Options SET: no=dr op=a */ #include <stdio.h> #include <math.h> #include <f_rt.h> void /*FUNCTION*/ x(a, m) double *a; int *m; { #define A(I_,J_) (a+(I_)*(*m)+(J_)) int i, j; for( i = 1; i <= *m; i++ ){ for( j = i + 1; j <= *m; j++ ){ *A(j - 1,i - 1) += 1; } } #undef A } /* end of function */ -- Steve Fullerton Statware, Inc. scf%statware.uucp@cs.orst.edu 260 SW Madison Ave, Suite 109 orstcs!statware!scf Corvallis, OR 97333 503/753-5382