Thread: Conversion from double to doublereal *

  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    6

    Conversion from double to doublereal *

    Hello,

    I'm trying to test the function cdgemm that I found here: http://www.netlib.org/clapack/cblas/dgemm.c

    I've left the function completely unchanged.
    I have the following main function here:

    Code:
    int main(){
        double *A, *B, *C;
        int m, n, k, i, j;
    	integer *m2,*n2,*k2;
        double alpha, beta;
    
    
    	
    
    
        printf ("\n This example computes real matrix C=alpha*A*B+beta*C using \n"
                " Intel® MKL function dgemm, where A, B, and  C are matrices and \n"
                " alpha and beta are double precision scalars\n\n");
    
    
        m = 2000, k = 200, n = 1000;
    
    
    	m2 = (integer *) m;
    	n2 = (integer *) n;
    	k2 = (integer *) k;
    
    
        printf (" Initializing data for matrix multiplication C=A*B for matrix \n"
                " A(%ix%i) and matrix B(%ix%i)\n\n", m, k, k, n);
        alpha = 1.0; beta = 0.0;
    
    
        printf (" Allocating memory for matrices aligned on 64-byte boundary for better \n"
                " performance \n\n");
        A = (double *) malloc( m*k*sizeof( double ));
        B = (double *) malloc( k*n*sizeof( double ));
        C = (double *) malloc( m*n*sizeof( double ));
    
    
    	char *a = (char *) 'N';
    	char *b = (char *) 'N';
        if (A == NULL || B == NULL || C == NULL) {
          printf( "\n ERROR: Can't allocate memory for matrices. Aborting... \n\n");
          free(A);
          free(B);
          free(C);
          return 1;
        }
    
    
        printf (" Intializing matrix data \n\n");
        for (i = 0; i < (m*k); i++) {
            A[i] = (double)(i+1);
        }
    
    
        for (i = 0; i < (k*n); i++) {
            B[i] = (double)(-i-1);
        }
    
    
        for (i = 0; i < (m*n); i++) {
            C[i] = 0.0;
        }
    
    
        printf (" Computing matrix product using Intel® MKL dgemm function via CBLAS interface \n\n");
        cdgemm(a, b, m2, n2, k2, alpha, A, k2, B, n2, beta, C, n2);
        printf ("\n Computations completed.\n\n");
    
    
        printf (" Top left corner of matrix A: \n");
        for (i=0; i<min(m,6); i++) {
          for (j=0; j<min(k,6); j++) {
            printf ("%12.0f", A[j+i*k]);
          }
          printf ("\n");
        }
    
    
        printf ("\n Top left corner of matrix B: \n");
        for (i=0; i<min(k,6); i++) {
          for (j=0; j<min(n,6); j++) {
            printf ("%12.0f", B[j+i*n]);
          }
          printf ("\n");
        }
        
        printf ("\n Top left corner of matrix C: \n");
        for (i=0; i<min(m,6); i++) {
          for (j=0; j<min(n,6); j++) {
            printf ("%12.5G", C[j+i*n]);
          }
          printf ("\n");
        }
    
    
        printf ("\n Deallocating memory \n\n");
        free(A);
        free(B);
        free(C);
    
    
        printf (" Example completed. \n\n");
        return 0;
    }
    I get an error : cannot convert parameter 6 from 'double' to 'doublereal *' referring to alpha and I'm guessing it's going to complain about beta as well once I resolve this one.

    Can anyone perhaps let me know how to convert from double to doublereal*?

    I've tried a similar approach as I have with m2,n2 and k2, meaning:

    Code:
    doublereal alpha2=(doublereal *) alpha;
    and other variations of this, but none of them worked.

    Any help will be greatly appreciated.
    Thank you in advance.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You need to learn how to program without using casts.
    Code:
        m2 = (integer *) m;
        n2 = (integer *) n;
        k2 = (integer *) k;
     
    ...
    
        char *a = (char *) 'N';
        char *b = (char *) 'N';
    Try say
    m2 = &m;

    and

    char *a = "N";




    > cdgemm(a, b, m2, n2, k2, alpha, A, k2, B, n2, beta, C, n2);
    Try something like
    cdgemm(a, b, m2, n2, k2, &alpha, A, k2, B, n2, &beta, C, n2);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2013
    Posts
    6
    Wonderful. Thank you very much and have a good day! *leaves a box of cookies for everyone*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. double conversion
    By shuo in forum C++ Programming
    Replies: 3
    Last Post: 01-21-2008, 12:11 AM
  2. float to double conversion
    By cdalten in forum C Programming
    Replies: 2
    Last Post: 04-12-2006, 08:05 AM
  3. Double to Int conversion warning
    By wiznant in forum C Programming
    Replies: 15
    Last Post: 09-19-2005, 09:25 PM
  4. Conversion from float to double
    By Ward in forum C++ Programming
    Replies: 17
    Last Post: 10-08-2003, 05:27 PM
  5. double to string conversion
    By tetriswhiz in forum C Programming
    Replies: 5
    Last Post: 04-25-2003, 11:41 AM

Tags for this Thread