<div dir="ltr"><div>Jayant, task parallelism will be useful if you can come up with a strategy to do partial calculations or data subsetting within subprocesses, in such a way as to reduce the size of intermediate results.  There are many possible strategies, depending on the kind of calculations.  For example, daily stats or partial sums or area averaging could be calculated in subprocesses, then reported back to the parent via relatively small Netcdf files.  Another way to think about strategy is dimension reduction along one or more dimensions of the original matrix.</div><div><br></div><div>Example 3 uses individual PNG plot files to communicate back to the parent.  These could just as easily be individual Netcdf files with dimension-reduced partial results.</div><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 21, 2021 at 7:14 AM Rick Brownrigg via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu">ncl-talk@mailman.ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Wow -- a 4320x56x450x900 floating-point variable is 391GB! In any case, NCL's subprocess feature can't be used for shared memory tasks -- the tasks are necessarily independent of each other.  I agree a 1.5hrs runtime is rather painful. But I don't know of a good way to speed that up. <br></div><div><br></div><div>Rick<br></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 21, 2021 at 1:00 AM Jayant <<a href="mailto:jayantkp2979@gmail.com" target="_blank">jayantkp2979@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi Rick,</div><div>Thanks again for your prompt response.</div><div>I have around 24 x 30 x 6months = 4320 files in binary format (along with a .ctl descriptor file for each). <br></div><div><ol><li>I read the ctl file first to get the record number of the variable of interest (say TEMP) and then;</li><li> use the <span style="font-family:monospace">fbinrecread</span> function to read the binary file. </li></ol><b>I guess the binary read takes a lot of time!</b> I define a 4-d variable (say inp_temp(4320,56,450,900)) in the beginning and then in a <span style="color:rgb(255,0,0)"><span style="font-family:monospace">do loop </span></span>over time, the above 2 steps are performed. After the do loop, I perform some daily and monthly stats and then generate monthly (6) plots or a vertical profile (pressure vs height) at a particular point over the entire period. To give an estimate on the execution time, it takes about an hour and half to complete.</div><div><br></div><div>In order to reduce time for the binary read, I was thinking of adopting the task parallelism for the <span style="color:rgb(255,0,0)"><span style="font-family:monospace">do loop</span></span> part of the script.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 21, 2021 at 1:38 AM Rick Brownrigg <<a href="mailto:brownrig@ucar.edu" target="_blank">brownrig@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi Jayant,</div><div><br></div><div>My apologies if I'm still not clear.  You say "It takes a lot of time to read a variable and generate a 
plot."  Are you trying to read 24 files and generate 24 plots? Or read 
24 files and perform analysis and generate plots from the composite?</div><div><br></div><div>It sounds like the latter -- are you trying to use subprocesses to read 24 files and end up with one array in memory composed from all 24 of them, so that you can perform analysis and/or plots on that array?  Then no -- subprocesses won't do the job and NCL in general does not have a way to perform concurrent reads into a shared memory space. The parent NCL script executing other programs via the subprocess() function has no communication with those programs.  <br></div><div><br></div><div>The "addfile<span style="color:rgb(255,0,0)">s</span>" function is the NCL way of reading multiple files into a common array; it is not concurrent to the best of my knowledge, but it does the job.<br></div><div><br></div><div>Rick<br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jul 20, 2021 at 9:04 PM Jayant <<a href="mailto:jayantkp2979@gmail.com" target="_blank">jayantkp2979@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Thanks Rick,</div><div>I want to use task parallelism. I have hourly files spanning a few months from a high resolution simulation. It takes a lot of time to read a variable and generate a plot. I have come across task parallelism (example 3) and want to modify the example such that I can use 24 processors to read 24 files at a time and save the desired variable in a parent array. And once the reading is complete, I can perform calculations (daily/monthly stats) on the parent array. I hope this helps understand what I intend to do.</div><div>You mentioned a file based approach...and perhaps the example 3 does save individual plots and later combine frames. I wonder if it's good idea in my case????</div><div>Best regards,</div><div>Jayant<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jul 20, 2021 at 11:50 PM Rick Brownrigg <<a href="mailto:brownrig@ucar.edu" target="_blank">brownrig@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi,</div><div><br></div><div>If I understand you correctly, you are trying to get the second script to update the array in the first script?  If so, that would not be possible, as the two scripts execute as independent processes, operating in independent memory spaces. They would need some other mechanism to communicate results between each other, perhaps something like a file-based approach. </div><div><br></div><div>Perhaps explain in more detail what you are trying to do and why there are two scripts involved, and others might be able to offer suggestions.<br></div><div><br></div><div>Rick</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jul 20, 2021 at 8:26 PM Jayant via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi,</div><div>I want to call one ncl script (test_second.ncl) from within another ncl script (test_prime.ncl) using <span style="font-family:monospace">system</span> command (in fact <span style="font-family:monospace">subprocess</span> command). In doing so, I want to update an array (defined in test_prime.ncl) in the second call. I am getting zeros (unchanged!!). How to proceed? Is there something like global variables that can be defined? Below are the working example scripts:</div><div>;==================================================</div><div><b>test_prime.ncl</b></div><div><span style="font-family:monospace">begin<br> ninp=10<br> <span style="color:rgb(255,0,0)">inparr</span>=new(ninp,float)<br> inparr=0.0<br><br> do i=0,ninp-1<br>  command="ncl -Q test_second.ncl "+str_get_sq()+"ip="+i+str_get_sq()+" "+str_get_sq()+"tmparr="+<span style="color:rgb(255,0,0)">inparr(i)</span>+str_get_sq()<br>  system(command)<br> end do<br>print(<span style="color:rgb(255,0,0)">inparr</span>)<br>end</span></div><div>;==================================================<br></div><div><b>test_second.ncl</b></div><div><span style="font-family:monospace">begin<br></span><div style="margin-left:40px"><span style="font-family:monospace">tmparr=ip ; intend to perform some calculation and update<br></span></div><span style="font-family:monospace">end</span></div></div></blockquote></div></blockquote></div></blockquote></div></blockquote></div></blockquote></div></blockquote></div></div>