3 Replies Latest reply on Mar 3, 2015 4:05 PM by jtrudeau

    Segmentation fault when using DGEMM

    kingds

      Hello everyone !

       

      I am using single threaded and multi threaded BLAS routine DGEMM of ACML 5.3.1 on my Linux PC(Ubuntu 12.04).

      1. CPU : Dual-Core AMD Opteron(tm) Processor 1216
        cpu flags       fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow rep_good nopl extd_apicid pni cx16 lahf_lm cmp_legacy svm extapic cr8_legacy
      2. g++ version : g++-4.6.real (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3.
      3. gfortran version : GNU Fortran (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

       

      I linked static library to my code. But when I excute my test code, I always get segmentation fault error.

      Why ? Am I doing something wrong ?

       

      Here are my test code

      //*********************************** main.cpp ***********************************
      #include "myheader.h"
      int main(int argc, char *argv[])
      {
          int dim = 4;
          int Num = dim * dim;
          //Matrix A
          double *A = new double [Num];
          Initialize_Random(dim, A);
          //Matrix B
          double *B = new double [Num];
          Initialize_Random(dim, B);
          //Matrix C
          double *C = new double [Num];
          Initialize_0(Num, C);
          //Variable
          const double alpha = 1;
          const double beta = 0;
          //Show Matrix
          showMat_C('A', dim, A);
          showMat_C('B', dim, B);
          //Call DGEMM from ACML
          std::cout <<">>>Calculate C = A * B by ACML_DGEMM" <<std::endl;
          acml_dgemm(alpha, dim, dim, dim, A, dim, B, dim,
                     beta, C, dim);
          showMat_C('C', dim, C);
          //free memory
          free(A);
          free(B);
          free(C);
          return (0);
      }
      

       

      //********************************** myheader.h ***********************************
      #include <iostream>
      #include <vector>
      #include <iomanip>
      #include <cmath>
      #include <cstdlib>
      //ACML DGEMM (Column Major)
      void acml_dgemm(double alpha, int m, int n, int k,
                      double *A, int ldA, double *B, int ldB,
                      double beta, double *C, int ldC);
      //Show Matrix
      void showMat_C(char X, int dim, double *data);
      //Get random data
      void Initialize_Random(int dim, double *B);
      //All data is 0
      void Initialize_0(int Num, double *C);
      

       

      #include "myheader.h"
      #include "acml.h"
      //ACML DGEMM (Column Major)
      void acml_dgemm(double alpha, int m, int n, int k,
                      double *A, int ldA, double *B, int ldB,
                      double beta, double *C, int ldC)
      {
          char TRANS = 'N';
          dgemm(TRANS, TRANS, m, n, k, alpha, A, ldA, B, ldB,
                beta, C, ldC);
      }
      //Show Matrix (Column Major)
      void showMat_C(char X, int dim, double *data)
      {
          int LD = dim;
          std::cout <<X <<" = " <<std::endl;
          std::cout <<std::setprecision(6);
          for (int i = 0; i < dim; ++i) {
              for (int j = 0; j < dim; ++j) {
                  int k = i + j * LD;
                  std::cout <<std::setw(10) <<std::right
                            <<std::fixed
                            <<data[k] <<"  " <<std::flush;
              }
              std::cout <<std::endl;
          }
      }
      //Get Random data
      void Initialize_Random(int dim, double *X)
      {
          int Num = dim * dim;
          for (int i = 0; i < Num; ++i) {
              X[i] = rand() % 100 * 0.01;
          }
      }
      //All data is 0
      void Initialize_0(int Num, double *C)
      {
          for (int i = 0; i < Num; ++i) {
              C[i] = 0;
          }
      }
      

       

      I have use GDB to check my code, and always get this.

      I tried link option

      1. -static -lacml -lgfortran (acml-5-3-1-gfortran64/gfortran64)
      2. -static -lacml_mp -lgfortran (acml-5-3-1-gfortran64/gfortran64_mp)

      but the result is same. Why do I always get SIGSEGV error ??

       

      A =
        0.830000    0.930000    0.490000    0.900000
        0.860000    0.350000    0.210000    0.590000
        0.770000    0.860000    0.620000    0.630000
        0.150000    0.920000    0.270000    0.260000
      B =
        0.400000    0.110000    0.820000    0.670000
        0.260000    0.680000    0.300000    0.350000
        0.720000    0.670000    0.620000    0.290000
        0.360000    0.290000    0.230000    0.020000
      >>>Calculate C = A * B by ACML_DGEMM
      C =
        1.250600    1.313000    1.470400    1.041700
        0.798600    0.644400    1.076100    0.771400
        1.204800    1.267600    1.418700    1.009300
        0.587200    0.898400    0.626200    0.506000
      Program received signal SIGSEGV, Segmentation fault.
      0x0000000000000000 in ?? ()