void scanRecursive(ATYPE *x, int n) { ATYPE *y; int from = 0; int to = n / 2; int i; if (n == 1) { return; } y = (ATYPE*) malloc(sizeof (ATYPE*) * (n / 2)); #pragma omp parallel for for (i = from; i < to; i++) { y[i] = x[2 * i] + x[2 * i + 1]; } scanRecursive(y, n / 2); x[1] = y[0]; #pragma omp parallel for for (i = from + 1; i < to; i++) { x[2 * i] = y[i - 1] + x[2 * i]; x[2 * i + 1] = y[i]; } if (n % 2 != 0) { x[n - 1] = y[n / 2 - 1] + x[n - 1]; } free(y); }
void Scanner::scan(ReleaseFileList &r,const QString &directory) { QStack<QString> dirname; QDir d(directory); if (d.exists()) { scanRecursive( d, r , dirname); } }
void Scanner::scanRecursive(QDir &d, ReleaseFileList &r, QStack<QString> &dirname) { QDirIterator it(d); static QString pathDelim="/"; while (it.hasNext()) { it.next(); QFileInfo info = it.fileInfo(); if (info.isDir()) { if (info.fileName()[0]=='.') { continue; } QDir nd(info.filePath()); dirname.push(info.fileName()); scanRecursive(nd, r,dirname); dirname.pop(); } else { QFile file(info.filePath()); ReleaseFile rf; if (file.open(QIODevice::ReadOnly) <0) { throw 2; } rf.sha = hashFile(file); dirname.push( info.fileName() ); rf.name = qstackJoin( dirname, pathDelim); rf.size = info.size(); rf.exec = info.isExecutable(); r.push_back(rf); dirname.pop(); file.close(); } } }
int main(int argc, char** argv) { ATYPE *x; int i, j; double start; for (j = ELEMENTS_STEP; j <= ELEMENTS; j += ELEMENTS_STEP) { x = (ATYPE*) malloc(sizeof (ATYPE*) * j); init(x, j); for (i = 1; i <= THREADS; i++) { omp_set_num_threads(i); start = omp_get_wtime(); scanRecursive(x, j); fprintf(stdout, "%d;%d;%f\n", j, i, omp_get_wtime() - start); } free(x); } fflush(stdout); return (EXIT_SUCCESS); }