Currently for a task, I am working with input files which give Matrix related test cases (Matrix Multiplication) i.e., example of an input file ->
N M
1 3 5 ... 6 (M columns)
....
5 4 2 ... 1 (N rows)
I was using simple read() to access them till now, but this is not efficient for large files of size > 10^2. So I wanted to know is there some way to use processes to do this in parallel.
Also I was thinking of using multiple IO readers based on line, so then each process could read different segments of the file but couldn't find any helpful resources.
Thank you.
PS: Current code is using this:
io:fread(IoDev, "", "~d")
2条答案
按热度按时间i34xakig1#
Did you consider to use
re
module? I did not make a performance test, but it may be efficient. In the following example I do not use the first "M N" line. So I did not put it in the matrix.txt file.matrix file:
I made the conversion in the shell
if you want to check the matrix size, you can replace the last line with:
7eumitmz2#
是否有某种方法可以使用进程来并行执行此操作。
当然可以了。
我也在考虑使用基于行的多个IO读取器,这样每个进程就可以读取文件的不同部分,但却找不到任何有用的资源。
您不是按行查找文件中的位置,而是按字节查找位置。虽然文件看起来像一堆行,但实际上文件只是一长串字符。因此,您需要确定要在文件中查找的字节位置。
检查文件:位置,文件:扩展。