#include <omp.h>
#include <fstream>
using std::ios_base;
using std::ofstream;
ofstream fi;
AcDbObjectIdArray ids;
void Bsort() {
if (prompt()) {
fi.open("bsort.txt", ios_base::app);
fi << "\nМассив" << ids.length() << "шт";
double t0 = omp_get_wtime();
if (filterBlockRef()) {
fi << "\nfilterBlockRef: " << omp_get_wtime() - t0;
double t1 = omp_get_wtime();
sortBlockRef();
fi << "\nsortBlockRef: " << omp_get_wtime() - t1;
t1 = omp_get_wtime();
drawBlockAtt();
fi << "\ndrawBlockAtt: " << omp_get_wtime() - t1;
fi << "\nОбщее время: " << omp_get_wtime() - t0;
}
fi.close();
}
}
void drawBlockAtt() {
AcString tag;
AcDbAttribute *at;
int value = 1;
int len = ids.length();
#pragma omp parallel for schedule(static) shared(ids, value)\
private(at) if(len > 2000) // распаралеливание потоков вывода
for (int i = 0; i < len; ++i) {
#pragma omp critical // отсутствие этой директивы приводит к критической ошибке
{
if (!acdbOpenObject(at, ids[i], kForWrite)) {
at->setTextString(tag.format(_RXST("%d"), value++).kwszPtr());
at->close();
}
}
}
}
//-------------------------------
// Результат выполнения:
//
// Массив: 20000шт
// filterBlockRef: 0.165681
// sortBlockRef: 0.00592158
// drawBlockAtt: 1.25335
// Общее время: 1.4265