我需要将一个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);
}
在函数
ParallelRead
中,我解析每一行,执行atoi
并填充矩阵。并行性是按行进行的,例如线程t解析行t,t + 1 * NUM_THREADS..
在一个有两个核心和2个线程的系统上,这需要。
Loading big file (fgets) : 5.79126
Preprocessing data (Parallel Read) : 4.44083
有没有更进一步优化的方法?