Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

OpenMP IO problem

weilo
Beginner
438 Views

Dear All,


I am trying to compare the time needed for writing a file between "-serial" version and "-openmp" with onethread doing the IO operation.
The result showed that;
Serial: 10.2 s
OpenMP: 19.2s
I'd like to know to some guidance to improve this.
Thanks in advance;

Chris

--Code
program Console1
!$ use omp_lib
implicit none
integer,parameter::nx=100,ny=100,nz=100
integer i,j,k
real start_time,finish_time
real A(nx,ny,nz)


A=1.0

start_time=secnds(0.0)
!$omp parallel
!$omp master
open(101,file='test1')
do k=1,nz
do j=1,ny
do i=1,nx
write(101,*) A(i,j,k)
end do
end do
end do
close(101)
!$omp end master
!$omp end parallel

finish_time=secnds(start_time)
print*,'time =', finish_time
end program Console1

0 Kudos
3 Replies
TimP
Honored Contributor III
438 Views
Did you actually set it to 1 thread, e.g. by setting OMP_NUM_THREADS=1 ? If not, I suppose you are totalling up the time spent in all threads. If the other threads aren't doing anything useful, you may be able to affect the time they spend by fiddling with options such as (for Intel OpenMP) KMP_BLOCKTIME.
I don't see the motivation for writing single datum formatted fields to a file, or for putting it in a parallel section.
When parallel sections are used for practical purposes, of course, it is at least as interesting to know the elapsed time as the total CPU time of all threads. I suppose it is possible that a parallel region, presumably with a critical region in the I/O run-time library, will take longer than a serial region, in case that is what you are trying to find out.
0 Kudos
Gergana_S_Intel
Employee
438 Views
Hi weilo,

I'll go ahead and move this thread to the "Threading on Intel Parallel Architectures" forum, which would be a more natural fit. You might get more guidance there.

Regards,
~Gergana
0 Kudos
jimdempseyatthecove
Honored Contributor III
438 Views
Quoting - weilo

Dear All,


I am trying to compare the time needed for writing a file between "-serial" version and "-openmp" with onethread doing the IO operation.
The result showed that;
Serial: 10.2 s
OpenMP: 19.2s
I'd like to know to some guidance to improve this.
Thanks in advance;

Chris

--Code
program Console1
!$ use omp_lib
implicit none
integer,parameter::nx=100,ny=100,nz=100
integer i,j,k
real start_time,finish_time
real A(nx,ny,nz)


A=1.0

start_time=secnds(0.0)
!$omp parallel
!$omp master
open(101,file='test1')
do k=1,nz
do j=1,ny
do i=1,nx
write(101,*) A(i,j,k)
end do
end do
end do
close(101)
!$omp end master
!$omp end parallel

finish_time=secnds(start_time)
print*,'time =', finish_time
end program Console1


The parallel version of the library function for "write" must take into consideration the possibility of multiple threads performing a write to the same unit at the same time. Therefor the mt version of the runtime library for write function must contain a critical section (hopefully on per unit). This will slow down the writes. Try reducing the number of calls to write

do k=1,nz
do j=1,ny
write(101,'(F10.3,/)') (A(i,j,k), i=1,nx)
end do
end do

You may have to experiment with the / and $ edit descriptors to get what you want.

Jim Dempsey
0 Kudos
Reply