Question

I am trying to use the culaSgels function in order to solve Ax=B.

I modified the systemSolve example of the cula package.

void culaFloatExample()
{
    int N=2;
    int NRHS = 2;
    int i,j;

    double cula_time,start_time,end_time;

    culaStatus status;

    culaFloat* A = NULL;
    culaFloat* B = NULL;
    culaFloat* X = NULL;

    culaFloat one = 1.0f;
    culaFloat thresh = 1e-6f;
    culaFloat diff;

    printf("Allocating Matrices\n");
    A = (culaFloat*)malloc(N*N*sizeof(culaFloat));
    B = (culaFloat*)malloc(N*N*sizeof(culaFloat));
    X = (culaFloat*)malloc(N*N*sizeof(culaFloat));

    if(!A || !B )
        exit(EXIT_FAILURE);

    printf("Initializing CULA\n");
    status = culaInitialize();
    checkStatus(status);

    // Set A
    A[0]=1;
    A[1]=2;
    A[2]=3;
    A[3]=4;

    // Set B 
    B[0]=5;
    B[1]=6;
    B[2]=2;
    B[3]=3;

    printf("Calling culaSgels\n");
    // Run CULA's version
    start_time = getHighResolutionTime();

    status = culaSgels('N',N,N, NRHS, A, N, A, N);

    end_time = getHighResolutionTime();
    cula_time = end_time - start_time;
    checkStatus(status);

    printf("Verifying Result\n");
    for(i = 0; i < N; ++i){
    for (j=0;j<N;j++)
    {
        diff = X[i+j*N] - B[i+j*N];
        if(diff < 0.0f)
            diff = -diff;
        if(diff > thresh)
            printf("\nResult check failed:  X[%d]=%f  B[%d]=%f\n", i, X[i+j*N],i, B[i+j*N]);

     printf("\nResults:X= %f \t B= %f:\n",X[i+j*N],B[i+j*N]);
    }
}


    printRuntime(cula_time);
    printf("Shutting down CULA\n\n");
    culaShutdown();

    free(A);
    free(B);

}

I am using culaSgels('N',N,N, NRHS, A, N, A, N); to solve the system but :

1) The results show me that every element of X=0 , but B is right. Also , it shows me the

Result check failed message

2) Studying the reference manual ,it says that one argument before the last argument (the A I have) ,should be the matrix B stored columnwised,but if I use "B" instead of "A" as parameter ,then I am not getting the correct B matrix.

Was it helpful?

Solution

Ok,code needs 3 things to work.

1) Change A to B ,so culaSgels('N',N,N, NRHS, A, N, B, N);

(I misunderstood that at exit B contains the solution)

2) Because CULA uses column major change A,B matrices accordingly.

3) Change to :

B = (culaFloat*)malloc(N*NRHS*sizeof(culaFloat));
X = (culaFloat*)malloc(N*NRHS*sizeof(culaFloat));

(use NHRS and not N which is the same in this example)

Thanks!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top