Hello everyone,
I'm new to C/C++. I'm trying to make a program that's going to use the CBLAS libraries that I downloaded on BLAS. After fighting tooth and nail with VC 2005 (I downgraded on purpose because at one point I was desperate.) with regards to solving compilation errors and such and eventually it all compiled just fine.
The problem now is, I get the above mentioned error. It says: "Unhandled exception at 0x0040271c in Try.exe: 0xC0000005: Access violation reading location 0x4e18feb8."
Now there are a few .cpp files (I'm compiling as C code.) which contain the functions and there is one other one which contains my main method. Using the debugger, it goes through 3 files all in all.
The main file:
Code:
/* cblas_example2.c */
#include <stdio.h>
#include <stdlib.h>
#include "cblas.h"
#include "cblas_f77.h"
#define INVALID -1
int main (int argc, char **argv )
{
int rout=-1,info=0,m,n,k,lda,ldb,ldc;
double A[2] = {0.0,0.0},
B[2] = {0.0,0.0},
C[2] = {0.0,0.0},
ALPHA=0.0, BETA=0.0;
printf("Checking if cblas_dgemm fails on parameter 11\n");
cblas_dgemm( CblasRowMajor, CblasNoTrans, CblasNoTrans, 0, 2, 2,
ALPHA, A, 1, B, 1, BETA, C, 1 );
return 1;
}
Then, at cblas_dgemm we proceed to:
Code:
/* *
* cblas_dgemm.c
* This program is a C interface to dgemm.
* Written by Keita Teranishi
* 4/8/1998
*
*/
#include "cblas.h"
#include "cblas_f77.h"
void cblas_dgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_TRANSPOSE TransB, const int M, const int N,
const int K, const double alpha, const double *A,
const int lda, const double *B, const int ldb,
const double beta, double *C, const int ldc)
{
char TA, TB;
#ifdef F77_CHAR
F77_CHAR F77_TA, F77_TB;
#else
#define F77_TA &TA
#define F77_TB &TB
#endif
#ifdef F77_INT
F77_INT F77_M=M, F77_N=N, F77_K=K, F77_lda=lda, F77_ldb=ldb;
F77_INT F77_ldc=ldc;
#else
#define F77_M M
#define F77_N N
#define F77_K K
#define F77_lda lda
#define F77_ldb ldb
#define F77_ldc ldc
#endif
int CBLAS_CallFromC;
int RowMajorStrg;
RowMajorStrg = 0;
CBLAS_CallFromC = 1;
if( Order == CblasColMajor )
{
if(TransA == CblasTrans) TA='T';
else if ( TransA == CblasConjTrans ) TA='C';
else if ( TransA == CblasNoTrans ) TA='N';
else
{
cblas_xerbla(2, "cblas_dgemm","Illegal TransA setting, %d\n", TransA);
CBLAS_CallFromC = 0;
RowMajorStrg = 0;
return;
}
if(TransB == CblasTrans) TB='T';
else if ( TransB == CblasConjTrans ) TB='C';
else if ( TransB == CblasNoTrans ) TB='N';
else
{
cblas_xerbla(3, "cblas_dgemm","Illegal TransB setting, %d\n", TransB);
CBLAS_CallFromC = 0;
RowMajorStrg = 0;
return;
}
#ifdef F77_CHAR
F77_TA = C2F_CHAR(&TA);
F77_TB = C2F_CHAR(&TB);
#endif
F77_dgemm(F77_TA, F77_TB, &F77_M, &F77_N, &F77_K, &alpha, A,
&F77_lda, B, &F77_ldb, &beta, C, &F77_ldc);
} else if (Order == CblasRowMajor)
{
RowMajorStrg = 1;
if(TransA == CblasTrans) TB='T';
else if ( TransA == CblasConjTrans ) TB='C';
else if ( TransA == CblasNoTrans ) TB='N';
else
{
cblas_xerbla(2, "cblas_dgemm","Illegal TransA setting, %d\n", TransA);
CBLAS_CallFromC = 0;
RowMajorStrg = 0;
return;
}
if(TransB == CblasTrans) TA='T';
else if ( TransB == CblasConjTrans ) TA='C';
else if ( TransB == CblasNoTrans ) TA='N';
else
{
cblas_xerbla(2, "cblas_dgemm","Illegal TransB setting, %d\n", TransB);
CBLAS_CallFromC = 0;
RowMajorStrg = 0;
return;
}
#ifdef F77_CHAR
F77_TA = C2F_CHAR(&TA);
F77_TB = C2F_CHAR(&TB);
#endif
F77_dgemm(F77_TA, F77_TB, &F77_N, &F77_M, &F77_K, &alpha, B,
&F77_ldb, A, &F77_lda, &beta, C, &F77_ldc);
}
else cblas_xerbla(1, "cblas_dgemm", "Illegal Order setting, %d\n", Order);
CBLAS_CallFromC = 0;
RowMajorStrg = 0;
return;
}
And finally to F77_dgemm which leads us to:
Code:
/* * Written by D.P. Manley, Digital Equipment Corporation.
* Prefixed "C_" to BLAS routines and their declarations.
*
* Modified by T. H. Do, 2/19/98, SGI/CRAY Research.
*/
#include <stdlib.h>
#include "cblas.h"
#include "cblas_test.h"
#define TEST_COL_MJR 0
#define TEST_ROW_MJR 1
#define UNDEFINED -1
void F77_dgemm(int *order, char *transpa, char *transpb, int *m, int *n,
int *k, double *alpha, double *a, int *lda, double *b, int *ldb,
double *beta, double *c, int *ldc ) {
double *A, *B, *C;
int i,j,LDA, LDB, LDC;
enum CBLAS_TRANSPOSE transa, transb;
get_transpose_type(transpa, &transa);
get_transpose_type(transpb, &transb);
if (*order == TEST_ROW_MJR) {
if (transa == CblasNoTrans) {
LDA = *k+1;
A = (double *)malloc( (*m)*LDA*sizeof( double ) );
for( i=0; i<*m; i++ )
for( j=0; j<*k; j++ )
A[i*LDA+j]=a[j*(*lda)+i];
}
else {
LDA = *m+1;
A = ( double* )malloc( LDA*(*k)*sizeof( double ) );
for( i=0; i<*k; i++ )
for( j=0; j<*m; j++ )
A[i*LDA+j]=a[j*(*lda)+i];
}
if (transb == CblasNoTrans) {
LDB = *n+1;
B = ( double* )malloc( (*k)*LDB*sizeof( double ) );
for( i=0; i<*k; i++ )
for( j=0; j<*n; j++ )
B[i*LDB+j]=b[j*(*ldb)+i];
}
else {
LDB = *k+1;
B = ( double* )malloc( LDB*(*n)*sizeof( double ) );
for( i=0; i<*n; i++ )
for( j=0; j<*k; j++ )
B[i*LDB+j]=b[j*(*ldb)+i];
}
LDC = *n+1;
C = ( double* )malloc( (*m)*LDC*sizeof( double ) );
for( j=0; j<*n; j++ )
for( i=0; i<*m; i++ )
C[i*LDC+j]=c[j*(*ldc)+i];
cblas_dgemm( CblasRowMajor, transa, transb, *m, *n, *k, *alpha, A, LDA,
B, LDB, *beta, C, LDC );
for( j=0; j<*n; j++ )
for( i=0; i<*m; i++ )
c[j*(*ldc)+i]=C[i*LDC+j];
free(A);
free(B);
free(C);
}
else if (*order == TEST_COL_MJR)
cblas_dgemm( CblasColMajor, transa, transb, *m, *n, *k, *alpha, a, *lda,
b, *ldb, *beta, c, *ldc );
else
cblas_dgemm( UNDEFINED, transa, transb, *m, *n, *k, *alpha, a, *lda,
b, *ldb, *beta, c, *ldc );
;
}
I get the above-mentioned exception in the last line, or:
Code:
cblas_dgemm( UNDEFINED, transa, transb, *m, *n, *k, *alpha, a, *lda,
b, *ldb, *beta, c, *ldc );
The debugger tells me what the address in the exception is the address if *ldc.
What am I doing wrong?
Any input will be greatly appreciated.
I apologise for the large amount of code, but I wanted to provide sufficient information and hopefully I've done that.
Thanks in advance.