Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fortran MPI programming...

Status
Not open for further replies.

tejattf

Programmer
Joined
Jun 16, 2010
Messages
2
Location
IN
Hi ..

Im new to Fortran and MPI...

Matrix addition Programme...

After compiling.. i got error like
forrtl: severe (24): end-of-file during read, unit -4, file stdin


include 'mpif.h'

Integer rank, size, ierr, status(MPI_STATUS_SIZE)
Integer npoc, init, final

real a(200), b(200), c(200)

call MPI_INIT(ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD, nproc, ierr)

print *, 'Enter Size of array:'

read *, size

if (rank .eq. 0 ) then

print *, 'Enter values to A:'

read *,(a(i), i=1,size)


print *, 'Enter values to B:'
read *,(b(i), i=1,size)

end if


blocksize= size/nproc

if ( rank .EQ. 0) then

do i=0, (nproc-1)

call MPI_Send(a(i*blocksize+1), blocksize, MPI_REAL, i, 1,
& MPI_COMM_WORLD, ierr)

call MPI_Send(b, blocksize, MPI_REAL, i, 1,
& MPI_COMM_WORLD, ierr)

end do

else


call MPI_Recv(a((rank-1)*blocksize+1),blocksize,MPI_REAL,0,1,
& MPI_COMM_WORLD,status,ierr)

call MPI_Recv(b, size, MPI_REAL, 0, 1,
& MPI_COMM_WORLD, status, ierr)


end if

if(rank .eq. 0) then

init= blocksize * (nproc - 1)+1;
final = size;

else

init= blocksize * (rank - 1)+1;
final= blocksize * rank;

end if



c(i)=0.

do i= 1, size

c(i)=a(i)+b(i)
end do



if ( rank .eq. 0) then

do i=1, size

call MPI_Recv(c,size,MPI_REAL,i,1,MPI_COMM_WORLD,status,ierr)
end do

do i=1, size
print *, c(i)
end do


else

call MPI_Send(c((rank-1)*blocksize),size,MPI_REAL,0,1,
& MPI_COMM_WORLD,status,ierr)

end if

call MPI_Finalize(ierr)

stop

end
thanks in advance...
 
I suspect that stdin is closed by mpiexec on all ranks but rank 0. You have a read command that all ranks will execute.
 
I changed prog like...


Ty for replying...
include 'mpif.h'

Integer rank, size, ierr, status(MPI_STATUS_SIZE)
Integer nproc, init, final
parameter(size=20)

real a(size), b(size), c(size)

call MPI_INIT(ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD, nproc, ierr)


if (rank .eq. 0 ) then

open(unit=7, file='par_vect.exe', status='unknown' )

print *, 'Enter Values for A:'

do i=1,size

read (7,*) a(i)

end do

do
print *, 'Enter values for B:'

read (7,*) b(i)

end do

end if


blocksize= size/nproc

if ( rank .EQ. 0) then

do i=0, (nproc-1)

call MPI_Send(a(i*blocksize+1), blocksize, MPI_REAL, i, 1,
& MPI_COMM_WORLD, ierr)

call MPI_Send(b, size, MPI_REAL, i, 1,
& MPI_COMM_WORLD, ierr)

end do

else


call MPI_Recv(a((rank-1)*blocksize+1),blocksize,MPI_REAL,0,1,

& MPI_COMM_WORLD,status,ierr)

call MPI_Recv(b, size, MPI_REAL, 0, 1,
& MPI_COMM_WORLD, status, ierr)


end if

if(rank .eq. 0) then

init= blocksize * (nproc - 1)+1;
final = size;

else

init= blocksize * (rank - 1)+1;
final= blocksize * rank;

end if



c(i)=0.

do i= 1, size

c(i)=a(i)+b(i)
end do



if ( rank .eq. 0) then

do i=1, size

call MPI_Recv(c,size,MPI_REAL,i,1,MPI_COMM_WORLD,status,ierr)
end do

! open(7, file='par_vect.exe')

do i=1, size

write (7,*) c(i)
end do

else

call MPI_Send(c((rank-1)*blocksize),size,MPI_REAL,0,1,
& MPI_COMM_WORLD,status,ierr)

end if

call MPI_Finalize(ierr)

close(7)

end


after running elap time is more than i expect...

in shell script i gave 1 node 2 proc... and outfile is *.exe file....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top