UDF and GNU Scientific Library

Unknown
edited July 2022 in Community Q&A

Hi guys,

I have been working with acuSolve user-defined function (UDF) for a while. To utilize the computational capacity of C-programming language, I plan to use GNU Scientific Library (which is a popular library to use with C) in my UDF.

Currenly, I am using a linux machine. I have successfully added path to the library in my .bashrc file and have sourced it properly. During gcc compilation, I am giving appropriate flags so that the libraries are linked properly during compilation. I have successfully compiled the UDF--there's no error during the compilation and I am able to obtain a libusr.so file.

The problem is during running "acuRun -libs libusr.so" command, I get an error during execution of acuSolve. I checked at the log file which has the following error information.

/home/.../altair/hwcfdsolvers/acusolve/linux64/bin/acuSolve-impi: symbol lookup error: libusr.so: undefined symbol: gsl_vector_alloc

BTW, gsl_vector_alloc is a command available in GNU Scientific Library. What should I do to rectify the error?

Thanks in advance.

Best Answer

  • acupro
    acupro
    Altair Employee
    edited July 2022 Answer ✓

    Thank you for your reply. Here are the details.

    image

     

    image

     

    image

     

    image

    It looks like you may need to copy one or more of the GSL libraries/.so files into the problem directory (same directory with the compiled libusr.so).  Maybe start with the libgsl.so file.

    Maybe try

    ldd libusr.so

    to see if it gives info on which libraries are needed/missing

Answers

  • acupro
    acupro
    Altair Employee
    edited July 2022

    Are you able to share at least the header portion for your UDF - where you include the GSL libraries - the 'include' lines - and any calls within the UDF itself that use those functions?  If so - please post here.

  • Unknown
    edited July 2022

    Are you able to share at least the header portion for your UDF - where you include the GSL libraries - the 'include' lines - and any calls within the UDF itself that use those functions?  If so - please post here.

    Thank you for your reply. Here are the details.

    image

     

    image

     

    image

     

    image

  • acupro
    acupro
    Altair Employee
    edited July 2022 Answer ✓

    Thank you for your reply. Here are the details.

    image

     

    image

     

    image

     

    image

    It looks like you may need to copy one or more of the GSL libraries/.so files into the problem directory (same directory with the compiled libusr.so).  Maybe start with the libgsl.so file.

    Maybe try

    ldd libusr.so

    to see if it gives info on which libraries are needed/missing

  • Unknown
    edited July 2022

    It looks like you may need to copy one or more of the GSL libraries/.so files into the problem directory (same directory with the compiled libusr.so).  Maybe start with the libgsl.so file.

    Maybe try

    ldd libusr.so

    to see if it gives info on which libraries are needed/missing

    Thanks a lot!

    Running ldd libusr.so didn't show necessary linkage with gsl library which was weird.

    Because I didn't get any error during command execution, I thought everything is correct. After adding necessary flags to link gsl, there's no error. The problem has resolved. I found that during the creation of shared library file (libusr.so file), I didn't link gsl library. 

    Thanks again.

  • acupro
    acupro
    Altair Employee
    edited July 2022

    Thanks a lot!

    Running ldd libusr.so didn't show necessary linkage with gsl library which was weird.

    Because I didn't get any error during command execution, I thought everything is correct. After adding necessary flags to link gsl, there's no error. The problem has resolved. I found that during the creation of shared library file (libusr.so file), I didn't link gsl library. 

    Thanks again.

    For others'/future information - would you please detail what you did to add 'necessary flags to link gsl'?  Was this in the UDF itself - or in the compiling (acuMakeLib) process?

  • Unknown
    edited July 2022

    For others'/future information - would you please detail what you did to add 'necessary flags to link gsl'?  Was this in the UDF itself - or in the compiling (acuMakeLib) process?

    This was during compiling process. The missing 'necessary flags to link gsl' are -lgsl -lgslcblas -lm.

     

  • acupro
    acupro
    Altair Employee
    edited July 2022

    This was during compiling process. The missing 'necessary flags to link gsl' are -lgsl -lgslcblas -lm.

     

    So this was when you compiled the separate 'double' GSL function - outside of the AcuSolve UDF - but called by that AcuSolve UDF.

  • Unknown
    edited July 2022

    So this was when you compiled the separate 'double' GSL function - outside of the AcuSolve UDF - but called by that AcuSolve UDF.

    Actually, I am compiling all the files together. Because UDF is written in C, it allows me to compile UDF along with another 'double' GSL function (C function) together. All of these files should be compiled together to create a common libusr.so file and 'necessary flags to link gsl' should be added. Also, header files for gsl library should be placed in the 'double' GSL C function.

    Finally, acuRun can be invoked.

  • acupro
    acupro
    Altair Employee
    edited July 2022

    Actually, I am compiling all the files together. Because UDF is written in C, it allows me to compile UDF along with another 'double' GSL function (C function) together. All of these files should be compiled together to create a common libusr.so file and 'necessary flags to link gsl' should be added. Also, header files for gsl library should be placed in the 'double' GSL C function.

    Finally, acuRun can be invoked.

    Sorry for the continued questions...

    Can you post your complete command to compile everything?

  • Unknown
    edited July 2022

    Sorry for the continued questions...

    Can you post your complete command to compile everything?

    Yeah, you can write GSL C code in the UDF itself and add necessary header files. However, for my convenience, I wrote separate GSL C function from UDF and called GSL C function from UDF.

    We have i. UDF ii. GSL C function.

    (We can have as many C functions as possible as long as necessary header files and environment path are set up and include all C files during gcc compilation).

    I didn't use acuMakeLib -src file1.c,file2.c. Instead, I used gcc command with necessary flags for the compilation. The command to compile everything is as follows:

    1. gcc -fPIC -DACUSIM_LINUX64 -c -I/home/.../altair/altair/hwcfdsolvers/acusolve/linux64/include -lgsl -lgslcblas -lm -O  file1.c file2.c

    (where ... denotes the username for the current profile)

    2. gcc -o libusr.so -shared -fPIC  file1.o file2.o -lm -lgsl -lgslcblas

    3. acuRun -libs libusr.so

  • acupro
    acupro
    Altair Employee
    edited July 2022

    Yeah, you can write GSL C code in the UDF itself and add necessary header files. However, for my convenience, I wrote separate GSL C function from UDF and called GSL C function from UDF.

    We have i. UDF ii. GSL C function.

    (We can have as many C functions as possible as long as necessary header files and environment path are set up and include all C files during gcc compilation).

    I didn't use acuMakeLib -src file1.c,file2.c. Instead, I used gcc command with necessary flags for the compilation. The command to compile everything is as follows:

    1. gcc -fPIC -DACUSIM_LINUX64 -c -I/home/.../altair/altair/hwcfdsolvers/acusolve/linux64/include -lgsl -lgslcblas -lm -O  file1.c file2.c

    (where ... denotes the username for the current profile)

    2. gcc -o libusr.so -shared -fPIC  file1.o file2.o -lm -lgsl -lgslcblas

    3. acuRun -libs libusr.so

    Thank you.  Most useful.