当前位置: 首页>>代码示例>>C++>>正文


C++ SquareMatrix::ToString方法代码示例

本文整理汇总了C++中SquareMatrix::ToString方法的典型用法代码示例。如果您正苦于以下问题:C++ SquareMatrix::ToString方法的具体用法?C++ SquareMatrix::ToString怎么用?C++ SquareMatrix::ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SquareMatrix的用法示例。


在下文中一共展示了SquareMatrix::ToString方法的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;
}
开发者ID:nrvru,项目名称:parallel-lab1,代码行数:81,代码来源:main.cpp


注:本文中的SquareMatrix::ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。