This is an example of the loops running (counting, summing), one instance per CPU independently. Although this code is parallel, it is doing the same thing on both CPUs.
to compile, use
mpif90 program_name.mpi.f90
to run on 2 CPUs, use
mpirun -np 2 ./a.out
Contents of "program_name.mpi.f90":
program exampleParallel
implicit none
include 'mpif.h'
INTEGER :: numcpu, rank, ierr
INTEGER :: loop1Indx, loop2Indx
INTEGER :: loop1Limit, loop2Limit
INTEGER :: numcpu, rank, ierr
INTEGER :: loop1Indx, loop2Indx
INTEGER :: loop1Limit, loop2Limit
INTEGER :: current_val, summd_val
loop1Limit=2
loop2Limit=3
current_val=0
summd_val=0
call MPI_INIT(ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD, numcpu, ierr)
write(*,*) 'Number of CPUs=',numcpu,' My rank=',rank
do loop1Indx = 1, loop1Limit
do loop2Indx = 1, loop2Limit
current_val = loop2Indx+(loop1Indx-1)*loop2Limit
write(*,*) current_val, ' from CPU ', rank
summd_val = summd_val+current_val
enddo
enddo
write(*,*) 'summed value is ', summd_val
call mpi_finalize(ierr)
end program