Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Parameter 5 was incorrect on entry to cblas_dgemm when running Intel example

Daniel_H_4
Beginner
1,484 Views

 

I have attempted compiling and running the example "Multiplying Matrices Using dgemm" in the online MKL tutorial; the URL is https://software.intel.com/en-us/node/529735.  I am using Visual C++ in Visual Studio 2013.

The code will compile successfully in debug mode, but at runtime, the cblas_dgemm(.) function call fails with the following message output to the screen:

"Intel MKL ERROR: Parameter 5 was incorrect on entry to cblas_dgemm."

Parameter 5 is the integer input k, representing the number of columns in the A matrix, and the number of rows in the B matrix.

I also attempted a simpler example, with a 2 x 3 matrix for A, and a 3 x 2 matrix for B, but the same error occurs (k = 3 here).  

The code is as follows:

/*	C source code is a simplified case based on Intel's dgemm_example.c:
	"Multiplying Matrices Using dgemm"
	See https://software.intel.com/en-us/node/529735
	In this simplified case, we attempt multiplication of a 2 x 3 matrix by
	a 3 x 2 matrix.  (m = 2, k = 3, n = 2; A(m x k) * B(k x n) = C(m x n))
*/

#include <stdio.h>
#include <stdlib.h>
#include "mkl.h"

int main()
{
	double *A, *B, *C;
	int i, j;
	int m = 2, k = 3, n = 2;
	double alpha = 1.0;
	double beta = 0.0;

	printf(" Allocating memory for matrices aligned on 64-byte boundary for better \n"
		" performance \n\n");
	A = (double *)mkl_malloc(m*k*sizeof(double), 64);
	B = (double *)mkl_malloc(k*n*sizeof(double), 64);
	C = (double *)mkl_malloc(m*n*sizeof(double), 64);
	if (A == NULL || B == NULL || C == NULL) {
		printf("\n ERROR: Can't allocate memory for matrices. Aborting... \n\n");
		mkl_free(A);
		mkl_free(B);
		mkl_free(C);
		return 1;
	}

	printf(" Intializing matrix data \n\n");
	A[0] = 11;
	A[1] = 12;
	A[2] = 13;
	A[3] = 21;
	A[4] = 22;
	A[5] = 23;

	B[0] = 1011;
	B[1] = 1012;
	B[2] = 1021;
	B[3] = 1022;
	B[4] = 1031;
	B[5] = 1032;

	C[0] = 0.0;
	C[1] = 0.0;
	C[2] = 0.0;
	C[3] = 0.0;

	printf(" Top left corner of matrix A before cblas_dgemm call: \n");
	for (i = 0; i< m; i++) {
		for (j = 0; j < k; j++) {
			printf("%12.0f", A[j + i*k]);
		}
		printf("\n");
	}

	printf("\n Top left corner of matrix B before cblas_dgemm call: \n");
	for (i = 0; i< k; i++) {
		for (j = 0; j < n; j++) {
			printf("%12.0f", B[j + i*n]);
		}
		printf("\n");
	}

	printf("\n Top left corner of matrix C before cblas_dgemm call: \n");
	for (i = 0; i< m; i++) {
		for (j = 0; j < n; j++) {
			printf("%12.5G", C[j + i*n]);
		}
		printf("\n");
	}

	printf(" Computing matrix product using Intel(R) MKL dgemm function via CBLAS interface \n\n");
	cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,
		m, n, k, alpha, A, k, B, n, beta, C, n);		
        // Error output to console here: 
        // "Intel MKL ERROR: Parameter 5 was incorrect on entry to cblas_dgemm."

	printf("\n Deallocating memory \n\n");
	mkl_free(A);
	mkl_free(B);
	mkl_free(C);

	printf(" Example completed, with runtime error. \n\n");	

	return 0;
}

This error seems very curious since a) it occurs with actual sample code in the tutorial, and b) is simply an integer matrix dimension.

In addition, I also discovered that if I chose the following for elements of the matrix A:

A[0] = 0.11;
A[1] = 0.12;
A[2] = 0.13;
A[3] = 0.21;
A[4] = 0.22;
A[5] = 0.23;

The values all get truncated to zero, despite the A array being defined as containing double types.

If anyone could help me figure out what is wrong above, particularly why the "Parameter 5" error is occurring, I would greatly appreciate it.

Thanks in advance.

 

 

 

 

0 Kudos
6 Replies
Murat_G_Intel
Employee
1,484 Views

Hi Daniel,

We do not see this error on our side. Could you please provide the following information:

* Compiler used for building the sample

* Your MKL link line

* IA32 or Intel64

Regarding to 0 truncation of the A matrix, please try the following change at line #56:

printf("%12.3f", A[j + i*k]);

 

Thank you,

Efe

0 Kudos
Daniel_H_4
Beginner
1,484 Views

Thanks Efe,

Here is the info I can provide:

* Compiler used for building the sample:  Visual C++ 2013

* IA32 or Intel64: Intel64

* Your MKL link line:  Not sure what to provide here, except that in the VC++ properties, I have C:\Intel\MKL\include set in "Include Directories", C:\Intel\MKL\em64t\lib set in "Library Directories", and the following libraries set explicitly under "Library Dependencies" in the Linker settings:

libiomp5md.lib
mkl_core.lib
mkl_intel_ilp64.lib
mkl_intel_lp64.lib
mkl_intel_thread.lib

In order to get my code to compile, I found that I needed to physically place libiomp5md.dll in the .../x64/debug directory (also did this for the release directory, but in the case where I compile in Release mode, the error is not noted in the output, even though the results are still wrong).

Hope this helps solve the problem.  I have had runtime errors with other sample code as well, but I'm hoping that by working through this one, it may be a configuration issue or something that fixes the other errors too.

As for the screen output, yes, if I put in "f", that should help.  I typically work in C++ and just use cout without formatting, so I missed that -- thanks.

Thanks again,

Dan

 

0 Kudos
mecej4
Honored Contributor III
1,484 Views

Libraries containing "ILP64" are for using with programs that call MKL routines with 64-bit integer arguments; for the more common 32-bit integer arguments, use libraries whose names contain "LP64", not "ILP64". It is definitely unusual (most probably, an error) to use both ILP64 and LP64 libraries in the same link step.

0 Kudos
Daniel_H_4
Beginner
1,484 Views

Thanks -- will give this a try.

0 Kudos
Daniel_H_4
Beginner
1,484 Views

By excluding the ILP64 library from the project settings, it seems to work now -- thanks very much!!  Will also give the other code examples another try now too.  I suspect the problems encountered in those cases should now be solved as well.

-Dan

0 Kudos
Ying_H_Intel
Employee
1,484 Views

Hi Dan, 

Thanks for letting us know. Just add some notes for your reference.

1) online MKL tutorial :   https://software.intel.com/en-us/mkl-tutorial-for-c

if intel compiler, it may simple compile as below 

  • Windows* OS: icl /Qmkl dgemm_example.c
  • Linux* OS, OS X*: icc -mkl dgemm_example.c

if with other compiler including Microsoft Visual studio,  please use the Intel MKL Link Line Advisor to generate a command line to compile and link the exercises in this tutorial: http://software.intel.com/en-us/articles/intel-mkl-link-line-advisor/

In general, it is 

mkl_intel_lp64.lib
mkl_intel_thread.lib
mkl_core.lib
libiomp5md.lib

2) ILP64 vs LP64. 

In general, we use LP64. 

  • The ILP64 interface

    It was used when in increased memory and also some legacy code requires 64-bit integers. Read more about the ILP64 interface and the libraries and functions supporting it in the Intel MKL User's Guide

3) about the libiomp5md.dll , it is Intel OpenMP multithread Run time library, was required when using threaded mkl library.  

Right, you can physically place libiomp5md.dll in the .../x64/debug directory.  But generally when install mkl, all of the environment variable should be added in system environment, we don't need to do this. 

To make all of required DLL ‘visible’ for the Microsoft .NET CLR and exe. There are some ways to do these, 

we usually add <paths_to_libs> to the system (or may be user) environment variable ‘path’

>>computer, right click>> open computer's properties page (Control Panel\System and Security\System)  =>Advanced System Setting => Advanced =>Environment Variables => path

add 

C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\redist\intel64_win\mkl;C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\redist\intel64_win\compiler:......... 

Best Regards,

Ying 

 

 

0 Kudos
Reply