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

## Solving a system of equation

Beginner
395 Views
I'm a beginner in using MKL library , Actually I want to solve a system of equation by calling dgetf and dgetrs function , but the segmentation fault error always appear when I run my program. The equation is Ax=B, which A is a dim*dim array and B is a dim array. Here is the part of my program which solves the system of equation
void Solve(int dim, double* A, double* B)
{
int* piv = new int [dim];
int info = 0;
int nhrs = 1;
char p = 'T';
dgetrf(&dim, &dim, A, &dim, piv, &info);
if(info)
{
printf("Fact failed -- %d\\n", info);
for(int i = 0; i < dim; i ++)
{
for(int j = 0; j < dim; j ++)
printf("%e\\t", A[i*dim+j]);
printf("\\n");
}
exit(0);
}
cout<<"\\n","\\n";
dgetrs(&p, &dim, &nhrs, A,&dim, piv, B, &dim, &info);
if(info)
{
printf("Solve failed -- %d\\n", info);
exit(0);
}
free(piv);
}
It would be highly appreciated if you can hel me .
10 Replies
Black Belt
395 Views
You have posted a fragment of a program. There is no point in listing all the possible ways in which that fragment could be expanded into a runnable program that causes a runtime error. Nor is there much to gain from posting one example of code that runs correctly, even though this is quite a bit easier to do.

Present a complete example and you will improve the chances that someone will tell you what the mistakes are.
Beginner
395 Views
Thanksfor your comment , I didn't get your meaning , here is the function which should solve my system of equation Ax=B, where A is the Matrix ofcoefficient, and in a n*n array , and b is the right side of my equation which is a n array . This is a complete example forexampleif youputA={1,2,1,2,1,1,1,1,0} and B={230} and send it ti the Sole the error segmentation fault appears.
Moderator
395 Views
I checked the problem with the version 10.2 Update7. win7. 32bit. No exceptions were found with the inputs you pointed.
for example - see the results after dgetrf
dgetrf passed -- 0
2.000000e+000 5.000000e-001 5.000000e-001
1.000000e+000 1.500000e+000 3.333333e-001
1.000000e+000 5.000000e-001 -6.666667e-001
Beginner
395 Views
Black Belt
395 Views
B={230} and send it ti the Sole the error segmentation fault appears

B={230} initializes only B[0], leaving B[1] and B[2] unset.

send it ti the Sole

????

Beginner
395 Views
sorry I mean B={2,3,0} not {230}.
Moderator
395 Views