This discussion is archived
8 Replies Latest reply: Jan 4, 2013 1:44 AM by 804536 RSS

Solaris studio OpenMP runtime library name

804536 Newbie
Currently Being Moderated
Hello:

Imagine I'm using some functions from the OpenMP API as omp_get_wtime(), for example. If I use gcc compiler I need to pass to the linker the order -lgomp as libgomp.a|so is the GNU OpenMP implementation (I know that I can pass -fopenmp instead the -lgomp, but I want to pass -lgomp for example in order to use omp_get_wtime() but not to activate other OpenMP directives in the program). If I use the Intel compiler, the order should be -liomp5 -lpthread and for PGI compilers -lpgmp

But what is the name of the solaris sturio OpenMP runtime library? Which flag should I pass to the linker in order to use the API functions of the OpenMP implementation? I know -xopenmp flag for activate OpenMP, but I want to link only the runtime library

Thanks
  • 1. Re: Solaris studio OpenMP runtime library name
    Steve_Clamage Pro
    Currently Being Moderated
    You don't say what language (C, C++, Fortran) you are using. The driver (cc, CC, or f90) causes the correct libraries to be linked in the correct order. The libraries to be linked depend on some command-line options, -xopenmp being one such option. (That is, the -xopenmp option causes the compiler to recognize OpenMP pragmas, and also ensures all needed libraries get linked.)

    If you add the "dry run" option to the command that links the final program, the driver emits the commands it would run in a real link. (The available "dry run" option spellings depend on the language and Studio version, but -xdryrun is typical.) You can inspect the "ld" command to see what libraries get linked, and in what order. Refer to the User Guide for the Studio compiler you are using.

    We don't recommend creating your own link command line instead of using the driver, because the correct command line (startup/finishup files, libraries, and their order) depends on the original set of options, and also depends on the Studio version. It's easy to forget to re-create the command every time it might change. Because it's a manual process, creating the command is also error-prone.

    In particular, if you only link the OpenMP library without any other setup, the library functions might not work correctly. The -xopenmp option allows the compiler to recognize OpenMP pragmas, and ensures the library will be properly initialized. Code that does not use OpenMP is not affected.

    Edited by: Steve_Clamage on Dec 31, 2012 11:26 AM
  • 2. Re: Solaris studio OpenMP runtime library name
    804536 Newbie
    Currently Being Moderated
    Hello, and thank you for your response:

    First of all, I'm using C with the driver suncc.

    Using the -xdryrun flag I see that a library called libmtsk (-lmtsk) is used. Actually are used -lmtsk, -lmtsk_crt plus an object file called. But when I try to use the flad -lmtsk in my program the linker says that libmtsk is not found. I'm trying to compile some programs similar to:

    int main()
    {
    double t=omp_get_wtime();
    #pragma omp for......
    for()....

    printf("Elapsed time: %lf seconds\n",omp_get_wtime()-t);
    return 0;
    }

    I want to check the elepsed time with and without OpenMP parallelization and I want to use always the OpenMP API function omp_get_wtime(). When I use the OpenMP code I all the compiler with the flag -xopenmp, but when I want to run the algorithm in serial version I can't use -xopenmp but I want to use the OpenMP time function, so I should to link the library (as -lgomp with gcc and -lpgmp with pgcc, etc)

    Cheers
  • 3. Re: Solaris studio OpenMP runtime library name
    Steve_Clamage Pro
    Currently Being Moderated
    Library libmtsk.so is part of Solaris, in the /lib or /usr/lib directory. It should be present on every system that has the basic programming packages. If you can build and run "hello world", libmtsk should be available. For example, this works for me:
    % cat z.c
    double omp_get_wtime();
    int main()
    {
        omp_get_wtime();
    }
    % cc z.c -lmtsk -xO3
    [ no messages ]
    % ./a.out
    [ no messages ]
    That is, it "works" in the sense of compiling and linking without errors. I don't know whether you can expect to use functions from the library with a roll-your-own program build, as opposed to using the -xopenmp option.

    But you don't have to resort to unusual solutions to avoid paralleliizing. Set the environment variable
    OMP_NUM_THREADS=1 
    at program run time to prevent more than one thread. You don't even have to recompile to try various numbers of threads. (The default for Studio is 2 threads, so you might want to set this variable anyway to a larger number for production runs.) Refer to the OpenMP User Guide for more information.
    You can find everything by starting at
    http://www.oracle.com/technetwork/server-storage/solarisstudio/overview/index.html
    All Studio user manuals are here:
    http://docs.oracle.com/cd/E24457_01/index.html
  • 4. Re: Solaris studio OpenMP runtime library name
    804536 Newbie
    Currently Being Moderated
    Hello Steve, and thank you for your answer:

    I have installex in a linux box the solaris studio 12.3 framework in the path /opt/sun/solarisstudio12.3
    In my /etc/bash.bashrc I have the lines:

    SUNPATH=/opt/sun/solarisstudio12.3/
    export PATH=$SUNPATH/bin:$PATH
    export MANPATH=$SUNPATH/man:$MANPATH

    in order to put in the PATH the binary directories. If I compile your example with the flag -xopenmp it runs ok, so I suppose libmtsk.so is installed. But when I try to link -lmtsk the message is clear:

    /usr/bin/ld: cannot find -lmtsk

    I have inspected the folders /opt/sun/solarisstudio12.3 and I found (thanks to use the flag -xdryrun you pointed me in your last post) the library in /opt/sun/solarisstudio12.3/prod/lib/compilers/rtlibs/usr/lib so I think this path are not known by the linker (but it is when -xopenmp is used). Why the library is stored in this strange path?

    I've tried to compila again with the order:

    suncc test.c -L/opt/sun/solarisstudio12.3/prod/lib/compilers/rtlibs/usr/lib -o test -lmtsk

    but I have again an error:

    /usr/bin/ld: skipping incompatible /opt/sun/solarisstudio12.3/prod/lib/compilers/rtlibs/usr/lib/libmtsk.so when searching for -lmtsk
    /usr/bin/ld: cannot find -lmtsk

    Incompatible libmtsk.so? Why?

    If I use for compilation the order:

    suncc test.c -o test /opt/sun/solarisstudio12.3/prod/lib/compilers/rtlibs/usr/lib/libmtsk.so

    the error is:

    /opt/sun/solarisstudio12.3/prod/lib/compilers/rtlibs/usr/lib/libmtsk.so: could not read symbols: File in wrong format

    Wrong format? I don't understand

    Why in your example the program compiles? Which version of suncc are ypu using? Is any bug in 12.3?

    Thanks

    Edited by: 801533 on 02-ene-2013 12:33

    Edited by: 801533 on 02-ene-2013 13:39
  • 5. Re: Solaris studio OpenMP runtime library name
    Steve_Clamage Pro
    Currently Being Moderated
    It helps to say what platform you are using at the start of the conversation. There are significant differences between (for example) Solaris and Linux. In addition, the only versions of Linux that we support are listed in the Release Notes for the version of Studio you are using. For Studio 12.3, only Oracle and Red Hat Linux v5 and v6 are supported.

    Since Solaris and Studio are Oracle (formerly Sun) products, we can arrange for Studio support libraries to be installed with the OS. Studio is considered the native compiler for Solaris. It is a guest on Linux.

    In the dry run output, you will see the linker command line has a -Y option with a list of paths. This option tells the linker where to look for libraries. When you use the -xopenmp option, the compiler driver adds the directory for libmtsk to the list of -Y paths. Otherwise not.

    But instead of continuing to pursue this complicated and error-prone process, why not try my suggestion of setting OMP_NUM_THREADS=1 ? Example:
    $ cc -xopenmp ... -o myprog
    $ OMP_NUM_THREADS=1 ./myprog
  • 6. Re: Solaris studio OpenMP runtime library name
    804536 Newbie
    Currently Being Moderated
    Thank you again for your answer:

    You are right, I should say my platform. I'm using an Intel Core i5 processor running Debian GNU/Linux (64 bits). I know that the compiler supports only Oracle and RHEL linuxes, but I have downloaded from Oracle and installed the file SolarisStudio12.3-linux-x86-bin.tar.bz2 in my Debian box without problems. The compiler seems to run very well, and the obtained results from the generated binaries are correct, so I suppose that the compiler runs too in Debian.

    Inspecting in detail the -xdryrun output I have found the actual path of libmtsk.so in my insyallation: /opt/sun/solarisstudio12.3/prod/lib/compilers/rtlibs/usr/lib/amd64

    Why this path is not loaded by default by the compiler as when I use -xopenmp, I don't know. Now, my program runs.

    The reason to use omp_get_wtime() function when I not use OpenMP pragmas is because not exists (at least I don't know) any method to obtain millisecond precision using ISO C99. I know functions as clock_gettime() but is only POSIX complaint. The OpenMP is not C99 of course, but OpenMP is present in almost all platforms and comes with the majority of moder compilers. If anyone knows an ISO C99 method to obtain millisecond (or better) precision to compute time, I would like to know about :)

    About your suggestion of compile the program with -xopenmp flag and run with OMP_NUM_THREADS=1, the execution of a program compiled without OpenMP and with OpenMP+OMP_NUM_THREADS=1 is not the same. The latter one is slower due to OpenMP in complicated loops with barriers or other OpenMP orders as flush() for example, so I need to compile pure non-OpenMP code. Other case is, for example, when you want to use the break clause inside a for loop that is possible to stop before the last iteration. In OpenMP the break sentence cannot be used and you should to use dirty tricks to simulate it. This makes a bit slower the OpenMP execution but with the correct number of processors is faster than serial code, but definitively running it with OMP_NUM_THREADS=1 is not a good idea.

    Thanks again for your time
  • 7. Re: Solaris studio OpenMP runtime library name
    Steve_Clamage Pro
    Currently Being Moderated
    The compiler driver creates search paths for the linker based on compiler options that determine what runtime libraries are needed. The mtsk library is assumed to be not needed when you don't use the -xopenmp option.

    You can get the non-OpenMP effect you want by compiling without the -xopenmp option and linking with the option. Example:
    cc -xO4 ... -c a.c b.c c.c 
    cc -xO4 -xopenmp ... a.o b.o c.o ... -o MyProg
    There is startup code in libmtsk that will add to overall run time (no matter how the library gets linked), but if you check timing within, for example, function main(), that small overhead won't show up.

    Our implementation of omp_get_wtime uses clock_gettime on Linux for hi-resolution time, and on Solaris uses gethrtime. You can tell at compile time whether you are on Solaris by using
    #ifdef __SunOS

    These functions would let you avoid libmtsk entirely when compiling in pure serial mode.

    Edited by: Steve_Clamage on Jan 3, 2013 9:53 AM
  • 8. Re: Solaris studio OpenMP runtime library name
    804536 Newbie
    Currently Being Moderated
    Hello:

    All clear now. Thanks for your time, Steve :)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points