I have a very strange situation with some of my tests regarding Paralell I / O. Here is the situation. I have several streams that open a file handler in the same file and read from a few places in the file (evenly spaced intervals) a finite number of bytes and upload them to an array. Everything is done using streaming streams. Now I assume that the hard drive should be slower due to random access search. This is why my tests actually target SSDs. It turns out that I hardly get any acceleration when reading the same file from a solid-state drive compared to a hard drive. I wonder what the problem is? This seems to be very surprising to me / I also post my code below to see what I'm doing exactly:
void readFunctor(std::string pathToFile, size_t filePos, BYTE* buffer, size_t buffPos, size_t dataLn, boost::barrier& barier) { FILE* pFile; pFile = fopen(pathToFile.c_str(), "rb"); fseek(pFile, filePos, SEEK_SET); fread(buffer, sizeof(BYTE), dataLn, pFile); fclose(pFile); barier.wait(); } void joinAllThreads(std::vector<boost::shared_ptr<boost::thread> > &threads) { for (std::vector<boost::shared_ptr<boost::thread> >::iterator it = threads.begin(); it != threads.end(); ++it) { (*it).get()->join(); } } void readDataInParallel(BYTE* buffer, std::string pathToFile, size_t lenOfData, size_t numThreads) { std::vector<boost::shared_ptr<boost::thread> > threads; boost::barrier barier(numThreads); size_t dataPerThread = lenOfData / numThreads; for (int var = 0; var < numThreads; ++var) { size_t filePos = var * dataPerThread; size_t bufferPos = var * dataPerThread; size_t dataLenForCurrentThread = dataPerThread; if (var == numThreads - 1) { dataLenForCurrentThread = dataLenForCurrentThread + (lenOfData % numThreads); } boost::shared_ptr<boost::thread> thread( new boost::thread(readFunctor, pathToFile, filePos, buffer, bufferPos, dataLenForCurrentThread, boost::ref(barier))); threads.push_back(thread); } joinAllThreads(threads); }
Now .. in my main file, I pretty much have ..:
int start_s = clock(); size_t sizeOfData = 2032221073; boost::shared_ptr<BYTE> buffer((BYTE*) malloc(sizeOfData)); readDataInParallel(buffer.get(), "/home/zahari/Desktop/kernels_big.dat", sizeOfData, 4); clock_t stop_s = clock(); printf("%f %f\n", ((double) start_s / (CLOCKS_PER_SEC)) * 1000, (stop_s / double(CLOCKS_PER_SEC)) * 1000);
Surprisingly, when reading from an SSD, I do not get acceleration compared to the HDD? Why could this be so?