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.

  • Leslie_9527wbc
    Leslie_9527wbc Altair Community Member

    I would like to ask about the solution on Windows, thanks!

  • acupro
    acupro
    Altair Employee

    Basic compiling user function on Windows uses acuMakeDll instead of acuMakeLib (for Linux).

    https://help.altair.com/hwcfdsolvers/acusolve/topics/acusolve/user_defined_function_programs_acumakedll.htm

  • Leslie_9527wbc
    Leslie_9527wbc Altair Community Member

    I write my UDF file and try to compile it in AcuSolve CMD by using AcuMakeDll and gcc compiler on Windows, but it doesn't work. This is my UDF and operation process, standalone C files can be compiled in AcuSolve CMD and executed, but those referencing the AcuSolve function library cannot be executed. thanks!

  • acupro
    acupro
    Altair Employee

    What is the output when you use

    acuMakeDll (and other options as necessary)

    to compile the function with the AcuSolve calls?

  • Leslie_9527wbc
    Leslie_9527wbc Altair Community Member

    I added paths that are involved "include & bin folder" of AcuSolve.

    The area enclosed by the red box is its output, it shows an undefined reference to 'udfCheckNumUsrVals', but the GSL library seems to have been found(?)

    My command is "gcc -o usr usr.c -I"C:\Program Files\Altair\2023\SimLab\bin\win64\solvers\Acusolve\acusolve\win64\include" -L"C:\Program Files\Altair\2023\SimLab\bin\win64\solvers\Acusolve\acusolve\win64\lib" -I"C:\gsl-2.8_build\include\gsl" -L"C:\gsl-2.8_build\lib" -lm -lgsl -lgslcbla"

  • mtanguay_
    mtanguay_
    Altair Employee

    Hi. Gcc using mingw is not supported. Your best bet is using Intel oneAPI compiler and VisualStudio linker. With regards to GSL, I don't know if it will work as-is or you would need to recompile it.

    Note that on Linux, you won't have the same problem and things should go smoothly using the acuMakeLib tool (just need to add the additional libs as arguments as per documentation).

    I know it is probably not the answer you were looking for but I hope it can help a bit.

  • Leslie_9527wbc
    Leslie_9527wbc Altair Community Member

    Ok, thanks. I think I will try another way to solve my question.