简体   繁体   中英

Multi-threads writing into a file C++

I have a big buffer with integer data (a big integer array) and I want to write it into a file.

However I am using openMP and my entire application is now multithreaded. So I wonder, after the buffer is full, is there a way for me to use openMP and have multiple threads writting into the same file making several read-only access to the buffer?

If with openMP it is impossible, is it possible to do it any other way? How should I do it?

Are there any libraries you know for doing this?

Multiple threads writing to a file will make the process even more slow than it already is, since this will force many seek operations (which are the slowest ones, considering default magnetic HDD's).

Consider writing the data to the disk with just one thread, but the reading being made with multiples threads accessing directly the in memory array. Once that array is not allocated anymore, the access should be performed at the disk, causing again a big slow down due to the seek times. To make reduce the slow down, you must implement some buffering scheme or use only one thread.

There are other things to be considered depending on how are your readings performed and your algorithm implemented, but I believe these are some of the general lines.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM