相关疑难解决方法(0)

在多线程应用程序中读取最快的文件

我必须将8192x8192矩阵读入内存.我想尽快做到这一点.
现在我有这个结构:

char inputFile[8192][8192*4]; // I know the numbers are at max 3 digits
int8_t matrix[8192][8192]; // Matrix to be populated

// Read entire file line by line using fgets
while (fgets (inputFile[lineNum++], MAXCOLS, fp));

//Populate the matrix in parallel, 
for (t = 0; t < NUM_THREADS; t++){
    pthread_create(&threads[t], NULL, ParallelRead, (void *)t);
}
Run Code Online (Sandbox Code Playgroud)

在函数中ParallelRead,我解析每一行,执行atoi并填充矩阵.并行性是线性的,就像线程t解析行一样t, t+ 1 * NUM_THREADS..

在具有2个线程的双核系统上,这需要

Loading big file (fgets) : 5.79126
Preprocessing data (Parallel Read) : 4.44083
Run Code Online (Sandbox Code Playgroud)

有没有办法进一步优化这个?

c++ multithreading file-read

8
推荐指数
2
解决办法
1万
查看次数

标签 统计

c++ ×1

file-read ×1

multithreading ×1