This forum has been archived. All content is frozen. Please use KDE Discuss instead.

CG and BiCGStab with OpenMP - no speedup

Tags: None
(comma "," separated)
lzhang
Registered Member
Posts
5
Karma
0
Hi there,

I have downloaded Eigen 3.3-alpha1 and played with it to solve a sparse matrix (row major) on an 8 cores machine. The test code is quite simple. I compiled it using g++ version 4.7.2 with -fopenmp option. But I didn't see any speedup. The Eigen::nbThreads() did tell me that there were 8 threads. The followings are part of the test code.

Code: Select all
typedef Eigen::SparseMatrix<double, Eigen::RowMajor>  MatrixType;
typedef Eigen::VectorXd  VecType;

void run_CG(const MatrixType& mat, const VecType& rhs,
            int maxIters, double tolerance,
            VecType& rst, int& nIters, double& estimateErr) {

    std::cout << "---------- CG ----------" << std::endl;
    Eigen::ConjugateGradient<MatrixType,
                             Eigen::Lower | Eigen::Upper,
                             Eigen::IdentityPreconditioner> cg;
    cg.setMaxIterations(maxIters);
    cg.setTolerance(tolerance);
    cg.compute(mat);
    rst = cg.solve(rhs);
    nIters = cg.iterations();
    estimateErr = cg.error();
}

void run_BiCGSTAB(const MatrixType& mat, const VecType& rhs,
            int maxIters, double tolerance,
            VecType& rst, int& nIters, double& estimateErr) {

    std::cout << "---------- BiCGStab ----------" << std::endl;
    Eigen::BiCGSTAB<MatrixType, Eigen::IdentityPreconditioner> cg;
    cg.setMaxIterations(maxIters);
    cg.setTolerance(tolerance);
    cg.compute(mat);
    rst = cg.solve(rhs);
    nIters = cg.iterations();
    estimateErr = cg.error();
}


I also tried to
Code: Select all
 grep -R "pragma omp" ./*
in the source directory of Eigen. But I didn't see and OpenMP directives.
So I was wondering if i used the wrong version or it is not supported yet.

Thanks,
LZ
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Very strange that you cannot find any pragma omp is Eigen's source, because even the 3.0 version has some omp directives. On 3.3-alpha1 you should see:

Code: Select all
$ grep "pragma omp" Eigen/* -R
Eigen/src/Core/products/GeneralMatrixMatrix.h:      #pragma omp critical
Eigen/src/Core/products/GeneralMatrixMatrix.h:        #pragma omp atomic
Eigen/src/Core/products/Parallelizer.h:  #pragma omp parallel num_threads(threads)
Eigen/src/SparseCore/SparseDenseProduct.h:        #pragma omp parallel for schedule(static) num_threads(threads)


The last one is responsible for multi-threading in sparse iterative solvers.
lzhang
Registered Member
Posts
5
Karma
0
Thank you! Problem sovled :)


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], q.ignora