Writing a performance analyzer need really simple help with subroutines

Click For Summary
SUMMARY

The forum discussion focuses on resolving syntax errors in a Fortran program that utilizes PAPI and ATLAS for performance analysis. Key issues include the incorrect placement of the "end program" statement, which should follow the main program's final "end do" statement, and the lack of variable declarations in the subroutines, leading to "unclassifiable statement" errors. Additionally, the use of the "implicit none" directive without proper variable declarations is highlighted as a source of confusion for the user.

PREREQUISITES
  • Understanding of Fortran programming syntax and structure
  • Familiarity with performance analysis libraries such as PAPI (version 3.6.2) and ATLAS
  • Knowledge of matrix operations and subroutine definitions in Fortran
  • Experience with error handling and debugging in Fortran
NEXT STEPS
  • Review Fortran syntax rules, particularly for subroutine and program structure
  • Learn about variable declaration and the implications of "implicit none" in Fortran
  • Explore the use of PAPI and ATLAS for performance measurement in scientific computing
  • Investigate common debugging techniques for Fortran programs to identify and resolve syntax errors
USEFUL FOR

This discussion is beneficial for novice Fortran programmers, performance analysts using PAPI and ATLAS, and anyone interested in optimizing matrix operations in scientific computing applications.

Machinus
Messages
3
Reaction score
0
I am getting a ton of errors trying to compile this. I am including PAPI and ATLAS calls but so far I think those calls are working ok.

For each subroutine, I am getting "unclassifiable statement" for the subroutine definition as well as "unexpected implicit none" and "expecting end program statement" at the end.

It also won't let me use abs to compare the matrices. I am sure my syntax is wrong but I am new to fortran and I am not sure how I am supposed to write it.

Code:
#include /mnt/scratch/sw/papi-3.6.2/include/fpapi.h

program main
implicit none

integer:: i,j,k,M,N
integer:: tinitial,tfinal
real(8):: epsilon
real(8):: r1,r2,r3,r4,r5,r6
real(8):: t1,t2,t3,t4,t5,t6
real(8), allocatable:: A(:,:),B(:,:),C(:,:),D(:,:)

epsilon = 2.22e-16

open(unit=1,file="optimization.dat")
do M=1,100

   N = 10*M

   allocate(A(N,N),B(N,N),C(N,N),D(N,N))

   call random_number(A)
   call random_number(B)
   call random_number(C)
   
   call m1(N,A,B,C,D)
   call m2(N,A,B,C,D)
   call m3(N,A,B,C,D)
   call m4(N,A,B,C,D)
   call m5(N,A,B,C,D)
   call m6(N,A,B,C,D)

   write(*,*) N,r1,r2,r3,r4,r5,r6
   write(1,*) N,t1,t2,t3,t4,t5,t6

end do

subroutine m1 (N,A,B,C,D)
implicit none
tinitial = rtime
do i=1,N
   do j=1,N
      do k=1,N
         C(i,j)=C(i,j)+A(i,k)*B(k,j)
      end do
   end do
end do
D(i,j)=C(i,j)
tfinal = rtime
t1 = tfinal-tinitial
call dgemm('No','No',N,N,N,1.0d0,A(N,N),i,B(N,N),k,1.0d0,C(N,N),i)
r1 = dlange(F,N,N,(C-D(i,j)))/(C*epsilon)
deallocate(A,B,C,D)
return
end subroutine m1

subroutine m2 (N,A,B,C,D)
implicit none
tinitial = rtime
do i=1,N
   do k=1,N
      do j=1,N
         C(i,j)=C(i,j)+A(i,k)*B(k,j)
      end do
   end do
end do
D(i,j)=C(i,j)
tfinal = rtime
t2 = tfinal-tinitial
call dgemm('No','No',N,N,N,1.0d0,A(N,N),i,B(N,N),k,1.0d0,C(N,N),i)
r2 = dlange(F,N,N,(C-D(i,j)))/(C*epsilon)
deallocate(A,B,C,D)
return
end subroutine m2

subroutine m3 (N,A,B,C,D)
implicit none
tinitial = rtime
do j=1,N
   do i=1,N
      do k=1,N
         C(i,j)=C(i,j)+A(i,k)*B(k,j)
      end do
   end do
end do
D(i,j)=C(i,j)
tfinal = rtime
t3 = tfinal-tinitial
call dgemm('No','No',N,N,N,1.0d0,A(N,N),i,B(N,N),k,1.0d0,C(N,N),i)
r3 = dlange(F,N,N,(C-D(i,j)))/(C*epsilon)
deallocate(A,B,C,D)
return
end subroutine m3

subroutine m4 (N,A,B,C,D)
implicit none
tinitial = rtime
do j=1,N
   do k=1,N
      do i=1,N
         C(i,j)=C(i,j)+A(i,k)*B(k,j)
      end do
   end do
end do
D(i,j)=C(i,j)
tfinal = rtime
t4 = tfinal-tinitial
call dgemm('No','No',N,N,N,1.0d0,A(N,N),i,B(N,N),k,1.0d0,C(N,N),i)
r4 = dlange(F,N,N,(C-D(i,j)))/(C*epsilon)
deallocate(A,B,C,D)
return
end subroutine m4

subroutine m5 (N,A,B,C,D)
implicit none
tinitial = rtime
do k=1,N
   do i=1,N
      do j=1,N
         C(i,j)=C(i,j)+A(i,k)*B(k,j)
      end do
   end do
end do
D(i,j)=C(i,j)
tfinal = rtime
t5 = tfinal-tinitial
call dgemm('No','No',N,N,N,1.0d0,A(N,N),i,B(N,N),k,1.0d0,C(N,N),i)
r5 = dlange(F,N,N,(C-D(i,j)))/(C*epsilon)
deallocate(A,B,C,D)
return
end subroutine m5

subroutine m6 (N,A,B,C,D)
implicit none
tinitial = rtime
do k=1,N
   do j=1,N
      do i=1,N
         C(i,j)=C(i,j)+A(i,k)*B(k,j)
      end do
   end do
end do
D(i,j)=C(i,j)
tfinal = rtime
t6 = tfinal-tinitial
call dgemm('No','No',N,N,N,1.0d0,A(N,N),i,B(N,N),k,1.0d0,C(N,N),i)
r6 = dlange(F,N,N,(C-D(i,j)))/(C*epsilon)
deallocate(A,B,C,D)
return
end subroutine m1

close(1)

end program

What are the obvious syntax problems and errors I am making?
 
Last edited:
Technology news on Phys.org
You have your end program in the wrong place. It and the close(1) statement should be at the end of your main program, right after the first end do. This might be what is causing the "unclassifiable statement" error.

For your implicit none statements in your subroutines, the problem might be that you're saying each subroutine has no implicitly typed parameters and variables, yet you're not declaring any of them in the subs.
 
  • Like
Likes   Reactions: Machinus

Similar threads

Replies
1
Views
2K
Replies
9
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 20 ·
Replies
20
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 22 ·
Replies
22
Views
5K