本文整理汇总了C++中SquareMatrix::GetNorm方法的典型用法代码示例。如果您正苦于以下问题:C++ SquareMatrix::GetNorm方法的具体用法?C++ SquareMatrix::GetNorm怎么用?C++ SquareMatrix::GetNorm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SquareMatrix
的用法示例。
在下文中一共展示了SquareMatrix::GetNorm方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MatrixMultiplication
void MatrixMultiplication(int matrix_size, bool is_print_matrices){
chrono::time_point<chrono::system_clock> start, end;
int elapsedTime, meanTime, i, x, y, threads_number;
SquareMatrix *result;
int resultTimes[NUMBER_OF_MULTIPLY_TYPES][MAX_THREADS];
float acceleration[NUMBER_OF_MULTIPLY_TYPES][MAX_THREADS];
float efficiency[NUMBER_OF_MULTIPLY_TYPES][MAX_THREADS];
cout << "Произведение матриц" << endl;
start = chrono::system_clock::now();
SquareMatrix * matrix1 = new SquareMatrix(matrix_size);
SquareMatrix * matrix2 = new SquareMatrix(matrix_size);
end = chrono::system_clock::now();
elapsedTime = chrono::duration_cast<chrono::milliseconds>(end - start).count();
cout << "Время генерации матриц:" << elapsedTime << "ms" << endl << endl;
if(is_print_matrices){
cout << "Матрица А:\n" + matrix1->ToString() << endl;
cout << "Матрица B:\n" + matrix2->ToString() << endl;
}
cout << "Однопоточная версия" << endl;
for(x = 0; x < NUMBER_OF_MULTIPLY_TYPES; x++) {
cout << "Выриант алгоритма " << getTextForMatrixMultiplyType(x) << endl;
meanTime = 0;
for (i = 0; i < REPETITIONS; i++) {
start = chrono::system_clock::now();
result = matrix1->MatrixMultiply(matrix2, MatrixMultiplyType(x));
end = chrono::system_clock::now();
meanTime += chrono::duration_cast<chrono::milliseconds>(end - start).count();
cout << "Норма матрицы: " << result->GetNorm() << endl;
delete result;
}
meanTime /= REPETITIONS;
cout << "Среднее время выполнения однопоточного умножения " << getTextForMatrixMultiplyType(x) << ": " << meanTime << "ms" << endl << endl;
resultTimes[x][0] = meanTime;
acceleration[x][0] = efficiency[x][0] = 1;
}
cout << "Многопоточная версия" << endl;
for(x = 0; x < NUMBER_OF_MULTIPLY_TYPES; x++) {
cout << "Выриант алгоритма " << getTextForMatrixMultiplyType(x) << endl;
for(y = 1; y < MAX_THREADS; y++) {
threads_number = y + 1;
meanTime = 0;
for (i = 0; i < REPETITIONS; i++) {
start = chrono::system_clock::now();
result = matrix1->MatrixMultiplyParallel(matrix2, MatrixMultiplyType(x), threads_number);
end = chrono::system_clock::now();
meanTime += chrono::duration_cast<chrono::milliseconds>(end - start).count();
cout << "Норма матрицы: " << result->GetNorm() << endl;
if (is_print_matrices) {
cout << "Матрица C:\n" + result->ToString() << endl;
}
delete result;
}
meanTime /= REPETITIONS;
cout << "Среднее время выполнения многопоточного умножения " << getTextForMatrixMultiplyType(x) <<
" (" << pluralizeThreads(threads_number) << "): " << meanTime << "ms" << endl << endl;
resultTimes[x][y] = meanTime;
acceleration[x][y] = (float)resultTimes[x][0]/resultTimes[x][y];
efficiency[x][y] = acceleration[x][y]/threads_number;
}
}
cout << "Результаты измерений" << endl;
for(x = 0; x < NUMBER_OF_MULTIPLY_TYPES; x++){
cout << "Вариант алгоритма " << getTextForMatrixMultiplyType(x) << endl;
cout << "Время выполнения: " << vectorToString(resultTimes[x], MAX_THREADS) << endl;
cout << "Коэффициент ускорения: " << vectorToString(acceleration[x], MAX_THREADS) << endl;
cout << "Коэффициент эффективности: " << vectorToString(efficiency[x], MAX_THREADS) << endl;
}
delete matrix1;
delete matrix2;
}