简体   繁体   English

对于小于 450 的值,Parallel Openmp 需要更多时间

[英]Parallel Openmp takes more time for value less than 450

I have written a code for Gaussian Elimination.我写了一个高斯消元的代码。 But it only works for N>450 & N<500 where N is the num of rows.但它只适用于 N>450 & N<500,其中 N 是行数。

For less than 450, it takes more time.低于450,需要更多时间。

For 500 or greater it shows nothing.对于 500 或更高,它什么也不显示。

#include <conio.h>
#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <math.h>
 #include <omp.h>




int main() {

    printf("\nGauss -\n");
    double dt_start, dt_stop;
    int i,j,k;
    float A[500][500],c,sum=0.0;
    int n=400;
    printf("Matrix\n");
    for(i=1; i<=n; i++){
        for(j=1; j<=(n+1); j++)
        {
            A[i][j]=1.0*rand()/20 + 1;

        }
    }


    //Serial execution
    dt_start=omp_get_wtime();
    for(j=1; j<=n; j++){ /*generation of upper triangular matrix serially*/
        for(i=1; i<=n; i++){
            if(i>j){
                c=A[i][j]/A[j][j];
                for(k=1; k<=n+1; k++)
                {
                    A[i][k]=A[i][k]-c*A[j][k];
                }
            }
        }
    }
    dt_stop=omp_get_wtime();
    printf("\nExecution time (Serially): %lf \n",dt_stop-dt_start);

    //parallel execution
    dt_start=omp_get_wtime();

    //#pragma omp parallel for

    for(j=1; j<=n; j++){
    /*generation of upper triangular matrix*/
    #pragma omp parallel for shared(A,j,n) private(i,c,k) default(none)
        for(i=1; i<=n; i++){
            if(i>j){
                c=A[i][j]/A[j][j];
                for(k=1; k<=n+1; k++){
                    A[i][k]=A[i][k]-c*A[j][k];
                }
            }
        }
    }
    #pragma omp barrier
    dt_stop=omp_get_wtime();
    printf("\nExecution time (parallelly): %lf \n",dt_stop-dt_start);


}


I have tried using different openmp commands but nothing seems to work.我尝试使用不同的 openmp 命令,但似乎没有任何效果。

Edit - It now works for 250 but not less than that.编辑 - 它现在适用于 250,但不少于 250。 Also, more than 500 it's not working另外,超过500它不起作用

I have written a code for Gaussian Elimination.我写了一个高斯消元的代码。

Why?为什么?

Use an optimized BLAS library and be done.使用优化的 BLAS 库并完成。 (There are many free optimized BLAS libraries, and they will do thing like cache-blocking and vectorization which you are not). (有许多免费优化的 BLAS 库,它们会做诸如缓存阻塞和矢量化之类的事情,而您却没有)。

See BLAS/LAPACK routine for doing Gaussian elimination for discussion of how your problem maps to BLAS.请参阅BLAS/LAPACK 例程进行高斯消元以讨论您的问题如何映射到 BLAS。

https://www.google.com/search?q=free+blas+library will find you a number of free BLAS libraries. https://www.google.com/search?q=free+blas+library会为您找到许多免费的 BLAS 库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM