calling pslaprnt from C

Open discussion regarding features, bugs, issues, vendors, etc.

calling pslaprnt from C

Postby tjcarroll » Tue Sep 07, 2010 8:35 am

Hi -
I think this is a simple issue, but I've been unable to figure it out. I'm translating my fortran scalapack code into C and everything has gone smoothly so far. However, I can't seem to figure out how to appropriately call pslaprnt to print my matrices.

Here was my fortran code:
Code: Select all
CALL PSLAPRNT( M, M, A, 1, 1, DESCA, 0, 0, 'A', 6, WORK )


Here is my new C code (where ONE, ZERO, and SIX are defined elsewhere):
Code: Select all
char *cmatnm="A";
pslaprnt_(&M, &M, A, &ONE, &ONE, descA, &ZERO, &ZERO, cmatnm, &SIX, WORK);


I suspect my problem is with parameter 9: cmatnm. When I run the code I get:

Code: Select all
[compute-0-0:12073] *** Process received signal ***
[compute-0-0:12073] Signal: Segmentation fault (11)
[compute-0-0:12073] Signal code: Address not mapped (1)
[compute-0-0:12073] Failing at address: 0x7bf000


I think it's some sort of pointer error with the pslaprnt line (when I remove that line, everything works perfectly of course). Sometimes the code works and sometimes I get this error, depending on what happens in the code above. Any help would be appreciated!

Thanks!
tom
tjcarroll
 
Posts: 10
Joined: Thu Nov 06, 2008 8:48 am

SOLVED! Re: calling pslaprnt from C

Postby tjcarroll » Mon Sep 13, 2010 5:31 pm

Hi,
I figured this out, so I thought I'd post the solution if anyone else is having the same issue. I know there are very few scalapack C examples available. I have discovered the solution for linux systems using gnu compilers:

If you are calling a fortran function from within C code:

1.) tack on an additional parameter to the end of the function call for each string
2.) the nth additional parameter is the length of the nth string
3.) I used a size_t for the type, but int also seems to work fine
4.) compile using libg2c. I had trouble getting this to work with -lg2c so I ended up doing it explicitly with: -L/usr/lib/libg2c.so.0.0.0

Here's the original call in my fortran code:

Code: Select all
CALL PSLAPRNT( M, M, A, 1, 1, DESCA, 0, 0, 'A', 6, WORK )


Here's the new call from C:

Code: Select all
int ZERO = 0;
int ONE = 1;
int SIX = 6;
char *matrixname="test";
int len_m = strlen(matrixname);
pslaprnt_(&M, &M, A, &ONE, &ONE, descA, &ZERO, &ZERO, matrixname, &SIX, WORK,len_m);


Note that the length of the string (len_m) is not passed by reference. I assume this is because the compiler/linker uses this information since it's not actually a parameter of the function.

Hope this helps someone!

-tom
tjcarroll
 
Posts: 10
Joined: Thu Nov 06, 2008 8:48 am


Return to User Discussion

Who is online

Users browsing this forum: Bing [Bot] and 4 guests