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

mkl_?csrcoo converter function

Bounrajbanditt_K_
初學者
3,388 檢視

Hi, 

I am trying to get this matrix format converter function to work in C. I checked and edited my program many times as well as checked the documentation but I always end up with the error:

INTEL MKL ERROR: Parameter 1 was incorrect on entry to MKL_DCSRCOO

which refers to the job array. I want to transform a sparse matrix in COO format to CSR format for use in PARDISO. 

I decided to test it out on the example matrix included under the Storage Format example of the mkl-2017-developer-reference-c.pdf

Here is my code snippet below:

int main () 
{
	MKL_INT job[6];
	MKL_INT n = 5;
	MKL_INT nnz = 13;
	MKL_INT info = 0; 

	double *acsr = calloc(nnz, sizeof(double));
	MKL_INT *ja = calloc(nnz, sizeof(MKL_INT));
	MKL_INT *ia = calloc(n+1, sizeof(MKL_INT));

	double acoo[] = { 1, -1, -3, -2, 5, 4, 6, 4, -4, 2, 7, 8, -5 };
	MKL_INT rowind[] = { 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5 };
	MKL_INT colind[] = { 1, 2, 4, 1, 2, 3, 4, 5, 1, 3, 4, 2, 5 };


	job[0] = 1;
	job[1] = 1;
	job[2] = 1;
	job[5] = 0;

	mkl_dcsrcoo(job, &n, acsr, ja, ia, &nnz, acoo, rowind, colind, &info);

	getchar(); 
	return 0; 
}

I am using the 2017 version of mkl. 
 

0 積分
1 解決方案
mecej4
榮譽貢獻者 III
3,388 檢視

If you open a Parallel Studio command prompt from the Start menu, and type "cl" (for the Visual C compiler) or "icl" (for the Intel C compiler), you will see the version of the compiler displayed.

I find that if I set up %INCLUDE% so that the Intel C-compiler's non-MKL-related include files are never used, the problems do not occur with older Visual C compilers. That is, if you use the Visual C compiler, and target x64, do not let it search for include files that came with the Intel C compiler, except for the MKL include files, and use an older version of the Visual compiler than 19.11.25507.1 .

UPDATE: I think that the real cause of the problems is that job[3] and/or job[4] are undefined. Some versions of the MKL documentation make no mention of what should go into job[3] (it is intended to specify whether the upper or lower triangle or the whole of the dense matrix is to be filled in), and says that job[4] should be set equal to nzmax in the case when job[0]=0. If this conjecture is correct, the bug should be easy to fix for the MKL team.

In the meantime, please set job[3] and job[4] to zero and see if that makes the problem go away.

在原始文章中檢視解決方案

12 回應
mecej4
榮譽貢獻者 III
3,388 檢視

I don't see any problem with the code snippet, provided you add the needed #include directives (at least stdio.h and mkl.h). What OS and which version/release of MKL/C compiler?

Bounrajbanditt_K_
初學者
3,388 檢視

Version/Release is 17.0.0.109 / 20160721. The initial release of Intel Parallel XE 2017.

Here are my includes in case it might help:

 

#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <mkl_lapacke.h>

#include "mkl.h"
#include "mkl_pardiso.h"
#include "mkl_types.h"
#include <time.h>

 

I am using Windows 7 Professional 64-bit (6.1, Build 7601) 

With processor: Intel(R) Xeon(R) CPU E5-1620 v3 @ 3.50GHz (8CPUs)

mecej4
榮譽貢獻者 III
3,388 檢視

I see the error, along with some compiler messages regarding redefinition of some macros in <math.h>, only when I use the Visual C compiler targeting x64, with the optimization option /Ot. No errors with the Intel C compiler. or with /Od with the Visual C compiler. No errors with either compiler when targeting x86. (See #6)

Bounrajbanditt_K_
初學者
3,388 檢視

I felt like I experimented with a variety of the above options to no avail, the error still persists.  

I am using Microsoft Visual Studio Community 2015 and I found out that the Intel Parallel Studio XE 2017 installed with it is Update 1 with Version 17.0.71.14. 

I'm not sure which compiler I'm using or how to switch but I did target x86 as well as messed with various optimization options with the same result. 

Appreciate the assistance thus far though. 

mecej4
榮譽貢獻者 III
3,389 檢視

If you open a Parallel Studio command prompt from the Start menu, and type "cl" (for the Visual C compiler) or "icl" (for the Intel C compiler), you will see the version of the compiler displayed.

I find that if I set up %INCLUDE% so that the Intel C-compiler's non-MKL-related include files are never used, the problems do not occur with older Visual C compilers. That is, if you use the Visual C compiler, and target x64, do not let it search for include files that came with the Intel C compiler, except for the MKL include files, and use an older version of the Visual compiler than 19.11.25507.1 .

UPDATE: I think that the real cause of the problems is that job[3] and/or job[4] are undefined. Some versions of the MKL documentation make no mention of what should go into job[3] (it is intended to specify whether the upper or lower triangle or the whole of the dense matrix is to be filled in), and says that job[4] should be set equal to nzmax in the case when job[0]=0. If this conjecture is correct, the bug should be easy to fix for the MKL team.

In the meantime, please set job[3] and job[4] to zero and see if that makes the problem go away.

Gagan
初學者
2,240 檢視

doing more checking brb

mecej4
榮譽貢獻者 III
3,388 檢視

Here are some details regarding the MKL bug. Stepping into the MKL routines in the VS debugger, I found the following lines of assembler:

00007FFDF93FDB70  cmp         dword ptr [rcx+8],1    #  job[2] > 1 ?
00007FFDF93FDB74  ja          00007FFDF93FDB4A  
00007FFDF93FDB76  cmp         dword ptr [rcx+10h],0  #  job[4] < 0 ?
00007FFDF93FDB7A  jl          00007FFDF93FDB4A  
00007FFDF93FDB7C  cmp         dword ptr [rcx+14h],3  #  job[5] > 3 ?
00007FFDF93FDB80  ja          00007FFDF93FDB4A  

Note that RCX contains the first argument to mkl_dcsrcoo, which is the pointer to the JOB array. In the example code, JOB = [1, 1, 1, ?, ?, 0]. The second compare instruction queries the value of JOB[4], which is not defined. If the junk value happens to be negative, things go wrong. I think that the manual should make it clear that JOB[4] should be set to zero, or the MKL code should be fixed.

Ying_H_Intel
主席
3,388 檢視

Hello, 

Please refer to MKL example dconverters.c, which be default in MKL install directory .   and it  provided the sample code about the function. 

for example 

MKL_INT job[8];

 job[0]=1;
      job[5]=2;
      mkl_scsrcoo (job,&n, Acsr, AJ,AI,&nnz,Acoo, ir,jc,&info); 

If it is still issue, please submit your question to our official support channel: Online Service Center - Intel Support

Best Regards

Ying

Gagan
初學者
2,240 檢視

see below.

 

MAKE SURE YOU COMPILE WITH -lmkl_intel_lp64 !

 

i recommend you don't add -DMKL_ILP64 -lmkl_intel_ilp64 to the command line, as i had issues with my test program when using them. but that's up to you and may be "against recommended usage".

 

what i can say is i had no problem converting a matrix with millions of elements when using -lmkl_intel_lp6

 

and as ying recommended, set the job array to 8, even though tis' probably not required

 

setting jobs[3] = 0 does nothing and should not do anything, either. its not the solution.

Gagan
初學者
2,222 檢視

TO ANYONE EXPERIENCING THIS ISSUE;

 

make SURE you are compiling with -lmkl_intel_lp64

 

i experienced this issue when converting CSR to COO and i was puzzled. this flag is important.

 

 

i do find it strange the compiler does not throw an error in the absence of this library, as compiling with

-lmkl_intel_thread -lmkl_core -lmkl_intel_ilp64

 

compile without issues, but exhibits the exact issue that stumped many people on this forum (and will continue to do so).

 

-lmkl_core -lmkl_intel_thread -lmkl_intel_lp64

 

and it seems to work.

Bounrajbanditt_K_
初學者
3,388 檢視

Yes you are right mecej4, it seems I need to initialize job[3] and job[4] to 0.  I was a bit confused as job[3] wasn't mentioned in the documentation and job[4] is used for when job[0] = 0 so I thought I can ignore it. I cannot express my gratitude enough.

 

Thank you both for the help.

mecej4
榮譽貢獻者 III
3,388 檢視

Glad to hear that the suggestion worked.

回覆