output intermediate results

General OpenMP discussion

output intermediate results

Postby lwxlee » Tue Nov 12, 2013 10:19 pm

Hi all,

I have a Fortran code and want to make it parallel. For ease of use, I selected OpenMP.
During the process, I want to dump some intermediate results to a txt file from each thread which is used to debug the code. The part of code relevant is like below:
Code: Select all
  !$OMP                   SCHEDULE(DYNAMIC,1)                                   
  do i=1,n_f
     !     angular frequency                                                   
     omega = 2.0_dpt*pit*f(i)
     !$ print*,'the frequency and angular freqency are ',f(i),omega             
     ! intialize                                                               
     SA = 0.0_dpt
     SB = 0.0_dpt                                                 
!     SA(1:sdof,1:sdof)               =   0.0_dpt                               
     SA(1:sdof,sdof+1:2*sdof)        =  -(K0 - omega**2*M)
     SA(sdof+1:2*sdof,1:sdof)        =  -(K0 - omega**2*M)
     SA(sdof+1:2*sdof,sdof+1:2*sdof) =  -K1                                                     
     SB(1:sdof,1:sdof)               =  -(K0 - omega**2*M)
!     SB(1:sdof,sdof+1:2*sdof)        =   0.0_dpt                               
!     SB(sdof+1:2*sdof,1:sdof)        =   0.0_dpt                               
     SB(sdof+1:2*sdof,sdof+1:2*sdof) =   K2
     !$ if (OMP_get_thread_num()==0) then                                       
     !$  call save_complex_data_2D('K0_thread1.out',K0)                         
     !$  print*,'size of K0 is ',shape(K0)                                     
     !$ end if                                                                 
     !$ if (OMP_get_thread_num()==1) then                                       
     !$    print*, 'size of K0 is ', shape(K0)                                 
     !$    call save_complex_data_2D('K0_thread2.out',K0)                       
     !$ endif

I created a subroutine as shown in the code to save the data. K0,K1,K2 and M are shared variables and they are only for reading.
The problem is that if I only use one loop and multiple threads, i.e., there are some threads idle, and then write the data to the .out file, I can get the right K0. However, when I tried to increase the outer loop size by using n_f >1 and let each thread busy, K0s of the dumped .out files become incorrect. Ideally, K0 should not change because they are only for read. I do not know what happened here. The sizes of the K0 of the dumped files are also different. Maybe this is a basic question but help is appreciated. Note that these save data subroutines work well for sequential code.

Posts: 2
Joined: Tue Nov 12, 2013 9:50 pm

Re: output intermediate results

Postby MarkB » Wed Nov 13, 2013 3:17 am

Hi there,

Does the code work correctly if you enclose the calls to the I/O routine in a CRITICAL construct?

Can you post the source code for save_complex_data_2D, please?
Posts: 746
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: output intermediate results

Postby lwxlee » Wed Nov 13, 2013 3:06 pm

Thanks, Mark. It is a silly mistake. In the save data subroutine, the index for the file to be written is same. When I tried to dump the data, the two files conflict which led to the to problem I met.
Posts: 2
Joined: Tue Nov 12, 2013 9:50 pm

Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 1 guest