SGGLSE called from a C interface throws a segmentation fault

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

SGGLSE called from a C interface throws a segmentation fault

Postby ykhalak » Mon Nov 04, 2013 2:25 pm

Hi. I'm trying to call SGGLSE from within C code (modification to the GROMACS package), but it keeps throwing a segmentation fault after entering this function:
Code: Select all
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff125f700 (LWP 10323)]
0x00007ffff5f5c583 in sgglse_ () from /usr/lib64/liblapack.so.3


Here is how I'm calling it:
Code: Select all
  float A[8]={1,1,1,1, 1,3,-1,1, 1,1,1,1};
  float c[4]={1,2,3,4};
  float B[2]={1,1, 1,1, 1,-1};
  float d[1]={7,4};
  float x[3];
  int lwork, info;
  lwork=9;
  real work[lwork];
 
  F77_FUNC(sgglse, SGGLSE) (4,
       3, 2, &A, 2, &B, 1,
       &c, &d, &x, &work, lwork, &info);


This is based on a test case I found in http://www.netlib.org/utk/people/JackDo ... K-2005.pdf
The F77_FUNC is a macro that works without problems in other parts of the GROMACS code to call LAPACK functions.
The LAPACK version I'm using is lapack-devel 3.4.1-4.1.2-x86_64 from the OpenSuse 12.2 repository.
I even tried to build LAPACK from source with the debug flag (-g), but couldn't get cmake from the GROMACS code I'm working with to find it as no .so file was produced.

Any help tracing down this segmentation fault would be greatly appreciated.
ykhalak
 
Posts: 1
Joined: Mon Nov 04, 2013 1:50 pm

Re: SGGLSE called from a C interface throws a segmentation f

Postby admin » Wed Dec 04, 2013 10:20 pm

Your matrices are the wrong size, and contain wrong data.
Below is a code that works fine (using LAPACKE - The C Standard Interface to LAPACK - included in the LAPACK package)

Code: Select all
#include  <stdio.h>
#include <lapacke.h>

int main()
{
  float A[12]={1,1,1,
               1,3,1,
               1,-1,1,
               1,1,1};
  float c[4]={1,2,3,4};
  float B[6]={1,1, 1,
              1, 1,-1};
  float d[2]={7,4};
  float x[3];
  lapack_int lwork, info;
  lwork=9;
  float work[lwork];
 
//CALL SGGLSE( M, N, P, A, LDA, B, LDB, C, D, X, WORK, LWORK, INFO ) 
info = LAPACKE_sgglse(LAPACK_ROW_MAJOR,
      4, 3, 2, A, 3 ,B, 3, c, d, x);

if (info ==0)
{
   printf ("Solution: \n");
   for (int i=0; i<3; i++) printf("%f ",x[i]);
   printf("\n");
}

return(info);
}



Makefile
Code: Select all
LIBS=-L/Users/julie/opt/mylib -llapacke -llapack -lrefcblas -lrefblas
IDIR =/Users/julie/opt/mylib
CC=gcc
CFLAGS=-I$(IDIR)
DEPS = lapacke.h
OBJ = prog.o

%.o: %.c $(DEPS)
   $(CC) -c -o $@ $< $(CFLAGS)

prog.exe: $(OBJ)
   gfortran -o $@ $^ $(CFLAGS) $(LIBS)

run : prog.exe
   ./prog.exe
   
clean:
   rm -f *.o *.exe *~ core


I strongly advice you to use LAPACKE to call LAPACK from C.
Hope it helps
Julie
admin
Site Admin
 
Posts: 468
Joined: Wed Dec 08, 2004 7:07 pm


Return to User Discussion

Who is online

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

cron