I/O write speed significantly slow (takes more than a hour)
My code solves a 2D problem. I recently increased the size of the domain (size of the arrays) significantly and a couple of problems are arose. Mostly about writing the results into "*.dat" files at the end of my code. The confusing part for me is that I have write commands at the beginning of the code in the main program and it is fast. However, the ones which are located in the write_result subroutine act significantly slow. Hopefully, I wish someone can give me some idea about the source of these problems.
I structured my code in a way where all the variables and constant parameters are declared in two separate modules. No other variable is specified elsewhere and all the subroutines (8-10 subroutines) use these modules. I did this because the variables can be used everywhere in all functions and subroutines without specifying their names as the inputs and outputs. In addition, it reduces the headache for tracking them and they all gathered and declared at one place. Here is an example of the way I structured my code.
domain size before : (150x100) code works fine
domain size after : (500*1000) write process takes so much.
RAM : 16GB used space while running the code: ~5 GB
all of the parameters
End Module 1
all of the arrays and variables
End Module 1
initiating the initial arrays (initial condition)
write initial condition into a *.dat file (takes 1 second)
starting the iterations
call subroutine A
call subroutine B
call subroutine write_result (with some frequency)
end the iterations when the condition is satisfied.
end program main
subroutine A(No need to declare the input and output of subroutines)
end subroutine A
subroutine B(No need to declare the input and output of subroutines)
end subroutine B
subroutine write_result (No need to declare the input and output of subroutines)
write the results into *.dat files. (takes long after I increased the size)
writing takes more than a hour......
end subroutine C