comparison src/Silvet.cpp @ 123:230920148ee5 bqvec-openmp

Simplify omp loop, leaving more to the omp scheduler
author Chris Cannam
date Wed, 07 May 2014 11:06:18 +0100
parents c4eae816bdb3
children 450f9987f041
comparison
equal deleted inserted replaced
122:7377032e0bf1 123:230920148ee5
409 409
410 int width = filtered.size(); 410 int width = filtered.size();
411 411
412 int iterations = 12; 412 int iterations = 12;
413 413
414 int stride = 8; 414 Grid pitchMatrix(width, vector<double>(processingNotes));
415
416 for (int i = 0; i < width; i += stride) {
417
418 int chunk = stride;
419 if (i + chunk > width) {
420 chunk = width - i;
421 }
422
423 vector<vector<double> > pitchSubMatrix
424 (chunk, vector<double>(processingNotes));
425 415
426 #pragma omp parallel for 416 #pragma omp parallel for
427 for (int k = 0; k < chunk; ++k) { 417 for (int i = 0; i < width; ++i) {
428 418
429 double sum = 0.0; 419 double sum = 0.0;
430 for (int j = 0; j < processingHeight; ++j) { 420 for (int j = 0; j < processingHeight; ++j) {
431 sum += filtered[i + k][j]; 421 sum += filtered.at(i).at(j);
432 } 422 }
433 423
434 if (sum < 1e-5) continue; 424 if (sum < 1e-5) continue;
435 425
436 EM em(m_hqMode); 426 EM em(m_hqMode);
437 for (int j = 0; j < iterations; ++j) { 427
438 em.iterate(filtered[i + k].data()); 428 for (int j = 0; j < iterations; ++j) {
439 } 429 em.iterate(filtered.at(i).data());
440 430 }
441 const double *pitches = em.getPitchDistribution();
442 431
443 for (int j = 0; j < processingNotes; ++j) { 432 const double *pitches = em.getPitchDistribution();
444 pitchSubMatrix[k][j] = pitches[j] * sum;
445 }
446 }
447 433
448 for (int k = 0; k < chunk; ++k) { 434 for (int j = 0; j < processingNotes; ++j) {
449 435 pitchMatrix[i][j] = pitches[j] * sum;
450 const vector<double> &pitches = pitchSubMatrix[k]; 436 }
451 437 }
452 Feature f; 438
453 for (int j = 0; j < processingNotes; ++j) { 439 for (int i = 0; i < width; ++i) {
454 f.values.push_back(float(pitches[j])); 440
455 } 441 Feature f;
456 fs[m_pitchOutputNo].push_back(f); 442 for (int j = 0; j < processingNotes; ++j) {
457 443 f.values.push_back(float(pitchMatrix[i][j]));
458 FeatureList noteFeatures = postProcess(pitches); 444 }
459 445 fs[m_pitchOutputNo].push_back(f);
460 for (FeatureList::const_iterator fi = noteFeatures.begin(); 446
461 fi != noteFeatures.end(); ++fi) { 447 FeatureList noteFeatures = postProcess(pitchMatrix[i]);
462 fs[m_notesOutputNo].push_back(*fi); 448
463 } 449 for (FeatureList::const_iterator fi = noteFeatures.begin();
450 fi != noteFeatures.end(); ++fi) {
451 fs[m_notesOutputNo].push_back(*fi);
464 } 452 }
465 } 453 }
466 454
467 return fs; 455 return fs;
468 } 456 }