OpenMP - Why does the number of comparisons decrease?
问题 I have the following algorithm: int hostMatch(long *comparisons) { int i = -1; int lastI = textLength-patternLength; *comparisons=0; #pragma omp parallel for schedule(static, 1) num_threads(1) for (int k = 0; k <= lastI; k++) { int j; for (j = 0; j < patternLength; j++) { (*comparisons)++; if (textData[k+j] != patternData[j]) { j = patternLength+1; //break } } if (j == patternLength && k > i) i = k; } return i; } When changing num_threads I get the following results for number of comparisons: