How does one link the optimized math library?

I have a simple C program calling pow() [see below], what is the proper way to compile in the optimized math library? The following do not work (can't find pow()):

% cc -fast -xarch=generic -o tmp tmp.c

nor

% cc -fast -xarch=generic -o tmp tmp.c -lmopt

(whereas if I compile with -lm, it does work, however I do not believe that is the optimized

library).

Thanks! Jordan

#include <stdio.h>

#include <math.h>

int

main()

{

fprintf(stderr, "Fubar=%d\n", pow(5.0, 3.2));

}

[567 byte] By [jslott] at [2007-11-26 9:36:01]
# 1

I believe with both of the cases below, you are getting the optimized pow() routine

from libmopt.

Just one of the things that the -fast option expands to is -xlibmopt. So your 2 compilation

lines are really the same.

Also, libmopt in Studio 11 is available only as a static library, libmopt.a. So this would

not show up when doing an ldd on your executable. See the Numerical Computation

Guide at :

http://docs.sun.com/app/docs/doc/819-3693?a=load

Section 3.2.2

You can verify this by starting your test case in dbx and then do :

% stop in __pow

% run

% whereis __pow

And you will get back `tmp`__pow

This means it used the __pow routine from the static libmopt and put it into the tmp exe.

Also, depending on how you use pow(), you may also want to look at the vectorized

pow() routine in libmvec.

jeremyweek at 2007-7-7 0:27:35 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2

Thanks for the reply! I suspected both of those compile lines were equivalent -- however,

neither of them work, as we see below. I thought that with -fast including -xlibmopt, that

would take care of it (Note: when I link -lm, it then works).

% cc -fast -xarch=generic -o tmp tmp.c

Undefinedfirst referenced

symbolin file

pow tmp.o

ld: fatal: Symbol referencing errors. No output written to tmp

%

What am I missing?

Thanks, Jordan

jslott at 2007-7-7 0:27:35 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3

Using Studio 11 on my SPARC system works :

% cc -V

cc: Sun C 5.8 2005/10/13

% cc -fast -xarch=generic -o tmp tmp.c

% ldd tmp

libc.so.1 =>/lib/libc.so.1

libm.so.2 =>/lib/libm.so.2

/platform/SUNW,Sun-Blade-2500/lib/libc_psr.so.1

Which version of Studio are you running? You can get this information by :

% version

Machine hardware:sun4u

OS version: 5.10

Processor type:sparc

Hardware:SUNW,Sun-Blade-2500

The following components are installed on your system:

Sun Studio 11

Sun Studio 11 C Compiler

Sun Studio 11 C++ Compiler

Sun Studio 11 Tools.h++ 7.1

Sun Studio 11 C++ Standard 64-bit Class Library

Sun Studio 11 Garbage Collector

Sun Studio 11 Fortran 95

Sun Studio 11 Debugging Tools (including dbx)

Sun Studio 11 IDE

Sun Studio 11 Debugger GUI

Sun Studio 11 Performance Analyzer (including collect, ...)

Sun Studio 11 X-Designer

Sun Studio 11 VIM editor

Sun Studio 11 XEmacs editor

Sun Studio 11 Native Connector Tool

Sun Studio 11 Performance Library

Sun Studio 11 LockLint

Sun Studio 11 Building Software (including dmake)

Sun Studio 11 Documentation Set

And are you on SPARC or Opteron platform?

jeremyweek at 2007-7-7 0:27:35 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 4

Yeah, Opteron... huh, my installation seems to be the same as yours.

% cc -V

cc: Sun C 5.8 2005/10/13

% version

Machine hardware:i86pc

OS version: 5.10

Processor type:i386

Hardware:i86pc

The following components are installed on your system:

Sun Studio 11

Sun Studio 11 C Compiler

Sun Studio 11 C++ Compiler

Sun Studio 11 Tools.h++ 7.1

Sun Studio 11 C++ Standard 64-bit Class Library

Sun Studio 11 Garbage Collector

Sun Studio 11 Fortran 95

Sun Studio 11 Debugging Tools (including dbx)

Sun Studio 11 IDE

Sun Studio 11 Debugger GUI

Sun Studio 11 Performance Analyzer (including collect, ...)

Sun Studio 11 X-Designer

Sun Studio 11 VIM editor

Sun Studio 11 XEmacs editor

Sun Studio 11 Native Connector Tool

Sun Studio 11 Performance Library

Sun Studio 11 Building Software (including dmake)

Sun Studio 11 Documentation Set

version of "/opt/SUNWspro/bin/../prod/bin/../../bin/cc": Sun C 5.8 2005/10/13

version of "/opt/SUNWspro/bin/../prod/bin/../../bin/CC": Sun C++ 5.8 2005/10/13

version of "/opt/SUNWspro/bin/../prod/bin/../../bin/f90": Sun Fortran 95 8.2 2005/10/13

version of "/opt/SUNWspro/bin/../prod/bin/../../bin/dbx": Sun Dbx Debugger 7.5 2005/10/13

version of "/opt/SUNWspro/bin/../prod/bin/../../bin/analyzer": Sun Performance Analyzer 7.5 2005/10/13

version of "/opt/SUNWspro/bin/../prod/bin/../../bin/dmake": Sun Distributed Make 7.7 2005/10/13

jslott at 2007-7-7 0:27:35 > top of Java-index,Development Tools,Solaris and Linux Development Tools...