MT1 samples

Midterm Sample Serial Code

  • Source code (matmul02.f90)
program MatMul02 
implicit none 
integer , parameter :: n=100
!
! The dimentions of the square matrix 
! Use n=100 for parallel code development
! After full tests, use n=1000 
! for both new serial and parallel runs
!
integer (kind=8) :: i,j,k 
real  (kind=16) :: sum, Csum, T(4)
real (kind=16), allocatable :: A(:,:), B(:,:), C(:,:)
allocate(A(n,n), B(n,n), C(n,n))
call  cpu_time (T(1)) 
do i = 1,n   
  do j = 1,n      
    A(i,j) = 1.0d0      
    B(i,j) = 2.0d0   
  enddo 
enddo
call  cpu_time (T(2)) 
do i = 1,n 
  do j = 1,n      
    sum = 0.d0      
    do k = 1, n         
      sum = sum + A(i,k) * B(k,j)      
    enddo      
    C(i,j) = sum   
  enddo 
enddo
call  cpu_time (T(3)) 
Csum=0.d0 
do i=1,n   
  do j = 1,n      
    Csum = Csum + C(i,j)   
  enddo 
enddo
call  cpu_time (T(4)) 
write(*,*) n, Csum 
write(*,"(' Initialize A and B, T2 - T1 =',1x,F12.5)") T(2)-T(1) 
write(*,"(' Multiply A and B  , T3 - T2 =',1x,F12.5)") T(3)-T(2) 
write(*,"(' Sum all C elements, T4 - T3 =',1x,F12.5)") T(4)-T(3) 
write(*,"(' Total time elapsed, T4 - T1 =',1x,F12.5)") T(4)-T(1)  
stop 
end
  • Makefile
all: 
	ifort matmul02.f90 -o matmul02.x  
sque: 
	qsub matmul02SRL.pbs 
clean: 
	rm  -f  *.x *.err *.out *.o
  • PBS script
#!/bin/bash 
#PBS -l walltime=01:00:00 
#PBS -q batch 
#PBS -N PBS-ser-MatMul2 
#PBS -V 
cd $PBS_O_WORKDIR 
hostname 
./matmul02.x