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

Segmentation Fault in LAPACKE_sgees

Croyfet
Beginner
627 Views

Problem

Segmentation Fault in LAPACKE_sgees

Question

I should be giving enough buffer to  LAPACKE_sgees (in Math Kernel Library) but when the following code run, a segmentation fault occurs in line 47. However, the comment in line 27 becomes active, this function succeeds and gives the correct result. This action is done in VC++ 2022.

And under the icx compiler, both of them failed.

How can I solve this problem and run this function safely?

Environment

  • Windows 10 21H2
  • Visual Studio 2022 Community
  • Visual C++ 2022 or Intel C++ Compiler (2022.1.0.256)
  • Intel libraries for oneAPI  (2022.1.0.256)

Code

 

#include <cstdint>
#include <cstdio>
#include <mkl.h>

namespace imkl
{
	constexpr int order = 3;
	constexpr int size = order * order;

	int ShapeArrayPrint(float* _A, int _side)
	{
		for (int i = 0; i < _side; i++)
		{
			for (int j = 0; j < _side; j++)
			{
				printf("%10lf ", _A[i * _side + j]);
			}
			printf("\n");
		}
		return 0;
	}
}

int main()
{

	//int _a = 0;

	float* mat_a = new float[imkl::size]
	{
		1, 2, 0,
		0, 3, 0,
		2, -4, 2
	};

	int* tmp_sdim = new int[imkl::size] {0};
	float* lpwr = new float[imkl::size] {0};
	float* lpwi = new float [imkl::size] {0};
	float* lpMat = new float[imkl::size] {0};

	imkl::ShapeArrayPrint(mat_a, imkl::order);

	printf("\n");

	int ret = LAPACKE_sgees
	(
		LAPACK_ROW_MAJOR, 'N', 'N', nullptr,
		imkl::order, mat_a, imkl::order, tmp_sdim,
		lpwr, lpwi, lpMat, imkl::order
	);

	imkl::ShapeArrayPrint(mat_a, imkl::order);

	printf("\n");

	delete[] tmp_sdim;
	delete[] lpwr;
	delete[] lpwi;
	delete[] lpMat;
	delete[] mat_a;

	return 0;
}

 

 

0 Kudos
1 Solution
Croyfet
Beginner
563 Views

Thank you for trying.

 

The cause may be linking to "*ilp.lib" lib files.

 

I added all lib files of mkl to the option of "Additional Dependencies". The lib files seem to have two types of library "LP interfaces" and "ILP interfaces". The former uses 32bits to index the array and the latter uses 64bits. You must set some options when you compile using "ILP interfaces".

 

I solved this by removing "*ilp.lib" libs from the option.

View solution in original post

0 Kudos
3 Replies
VidyalathaB_Intel
Moderator
588 Views

Hi,


Thanks for reaching out to us.

Could you please attach your VS project file here so that we can try reproducing the issue?

I've tried running the provided code on my end in both VS2022 and Intel oneAPI command prompt with icx compiler (Intel C++ Compiler (2022.1.0.256)) but could not see the segementation fault error which you are mentioning and the output displayed is as shown below

 

1.000000  2.000000  0.000000

 0.000000  3.000000  0.000000

 2.000000 -4.000000  2.000000


 2.000000  2.000000 -4.000000

 0.000000  1.000000  2.000000

 0.000000  0.000000  3.000000


Additionally, we suggest you try running the code from Intel oneAPI command prompt and see if the issue still persists.

Command:

> icx /Qmkl *.cpp


Regards,

Vidya.


0 Kudos
Croyfet
Beginner
564 Views

Thank you for trying.

 

The cause may be linking to "*ilp.lib" lib files.

 

I added all lib files of mkl to the option of "Additional Dependencies". The lib files seem to have two types of library "LP interfaces" and "ILP interfaces". The former uses 32bits to index the array and the latter uses 64bits. You must set some options when you compile using "ILP interfaces".

 

I solved this by removing "*ilp.lib" libs from the option.

0 Kudos
VidyalathaB_Intel
Moderator
553 Views

Hi,

 

>>The lib files seem to have two types of library "LP interfaces" and "ILP interfaces"

Yes, there are two types of interfaces LP64 and ILP64.

Here is the link with more details regarding the same.

https://www.intel.com/content/www/us/en/develop/documentation/onemkl-windows-developer-guide/top/linking-your-application-with-onemkl/linking-in-detail/linking-with-interface-libraries/using-the-ilp64-interface-vs-lp64-interface.html

>>I solved this by removing "*ilp.lib" libs from the option.

Glad to know that your issue is resolved.

Please post a new question if you need any additional assistance from Intel as this thread will no longer be monitored.

 

Regards,

Vidya.

 

0 Kudos
Reply