Quantcast
Channel: Fortran
Viewing all articles
Browse latest Browse all 3108

open file using newunit directive, threadsafe fortran

$
0
0

HI Lorri, others,

I have just one more question before I dive in and try to play

with rewriting parts of my application for threadsafe, and it

relates to reading the input data.  

Each thread independently processes in the same way , without any sharing

of results between the threads, data from the single data file submitted to the thread.

The file is identified by a full path, such as c:\mydatafiles\exmpl001.dat as the first argument from the c== calling interface

The results of the processing at the end of each thread are passed back out to the interface

to be reported there, and the thread is closed. In many instances the results are just written back to the interface

in memory. In some applications the results are written out to a physical data file, but first I will be trying how things work

just with the memory dump, to reduce the file handling needed with the writing. 

 

Each file has the same binary file format, but different data.  Since some of the files could have a lot more data than others

the processing time and usage of features in the subroutines will be different between the threads.

 

Would this general approach be expected to work ----:???

The only file reading is done in the main routine using

open(newunit=NWI8,file=DSNX,form='binary') 

up front as the first task as soon as the data path and file name are parsed

such as DSNX = C:\mydata\exmpl001.dat,  then do all the file reading in the main routine into arrays,

close the unit NWI8, and then pass the arrays via argument lists to the subroutines downstream.

When I am doing this, I would expect that a valid & different value of NWI8 would be generated for each thread,

so the correct data file would be read in each thread without racing. Should I expect that this would work????

OR,

Should I expect that I have to take more precautions to manage the overall process, such as

I have to have the c++ calling interface that wants to do multithreading to my main program rewritten provide a different

valid unit number to me --  currently the c++ calling interface is only passing the path of the datafile,

and I have no information for how many total threads (meaning individual datafiles that might be wanting to run concurrently).  

Today all I have from the c++ interface is stdcall  myprogram(datafilepath, ......other processing arguments)

whereas I might have to have the calling interface rewritten such as stdcall myprogram(unit number,datafilepath,max number of

threads, .......other processing arguments) 

 

Finally,  am I correct in assuming that it is better to do all the file reading in the main routine, even though it would be

better & more elegant if I could use a variation of the file reading, which currently is its own subroutine???

 

thanks for your advice and patience with my questions...

Bill

 

 

 

 

 


Viewing all articles
Browse latest Browse all 3108

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>