Facing linking trouble with mkl in linux Intel compiler (icc) - dynamic-linking

here is the command line in linux:
icc test.c -o test.o -L/opt/intel/current/mkl/intel64 -I/opt/intel/current/mkl/include -lmkl_intel_ilp64 -lmkl_core -lmkl_scalapack_ilp64
after running this command: I got a long line of undefined reference errors. I have also tried in eclipse but could not resolve the linking problem there too. I would be happy if anyone just help me to run a small code like this:
//test.c- a sample code from user guide
#include "mkl.h"
#define N 5
void main()
{
int n, inca = 1, incb = 1, i;
typedef struct{ double re; double im; } complex16;
complex16 a[N], b[N], c;
void zdotc();
n = N;
for( i = 0; i < n; i++ ){
a[i].re = (double)i; a[i].im = (double)i * 2.0;
b[i].re = (double)(n - i); b[i].im = (double)i * 2.0;
}
zdotc( &c, &n, a, &inca, b, &incb );
printf( "The complex dot product is: ( %6.2f, %6.2f) ", c.re, c.im );
}
my server
> MKLROOT: /opt/intel/current/mkl/
> library: $MKLROOT/lib/intel64/
> include:$MKLROOT/include
ICC 64bit is installed.
thanks in advance.

The best way to get right linkline for Intel MKL is using MKL Linkline Advisor. Even with right LD_LIBRARY_PATH compiler options and set of libraries you link doesn't look right. Should be
-DMKL_ILP64 -I$(MKLROOT)/include -L$(MKLROOT)/lib/intel64 -lmkl_intel_ilp64 -lmkl_intel_thread -lmkl_core -openmp -lpthread -lm

Related

NaN's are getting reported as 0 while compiling with icpx and not as NaN

On running this program, in the output Nan"s are being reported as 0, when building with icpx V2022.1, it is working fine with other compilers.
Compiling with the command: icpx -O3 -qmkl=sequential
#define ARMA_DONT_USE_WRAPPER
#include <armadillo>
int main() {
arma::Col<double> var;
var.randu(4);
var.print();
std::cout << std::endl;
var[0] = arma::datum::nan;
// Same with var[0] = std::numeric_limits<double>::quiet_NaN()
var.print();
return 0;
}
The Intel compilers' default optimization setting is -O2.
As suggested by Peter Cordes in the above comment, You can use the command"-fp-model=precise" flag, to instruct the compiler to strictly follow value-safe optimizations when implementing floating-point computations.
Hope this solves the issue.

Error compiling E-ACSL FRAMA-C

I am new to Frama-C framework and I am trying to do some contract testing with C programs. I intend to use E-ACSL plugin for this, and I tried a test program to see how it works, but I get some compilation errors. Here is my code:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int x = 0;
/*# assert x == 1;*/
/*# assert x == 0;*/
return 0;
}
Then, here is the Frama-C annotated code:
/* Generated by Frama-C */
#include "stdio.h"
#include "stdlib.h"
struct __e_acsl_mpz_struct {
int _mp_alloc ;
int _mp_size ;
unsigned long *_mp_d ;
};
typedef struct __e_acsl_mpz_struct __e_acsl_mpz_struct;
typedef __e_acsl_mpz_struct ( __attribute__((__FC_BUILTIN__)) __e_acsl_mpz_t)[1];
/*# ghost extern int __e_acsl_init; */
/*# ghost extern int __e_acsl_internal_heap; */
extern size_t __e_acsl_heap_allocation_size;
/*#
predicate diffSize{L1, L2}(ℤ i) =
\at(__e_acsl_heap_allocation_size,L1) -
\at(__e_acsl_heap_allocation_size,L2) ≡ i;
*/
int main(void)
{
int __retres;
int x = 0;
/*# assert x ≡ 1; */ ;
/*# assert x ≡ 0; */ ;
__retres = 0;
return __retres;
}
Finally, I try to compile it with gcc and the flags the manual indicates (page 13) but I get the following errors (and warnings):
$ gcc monitored_second.c -o monitored_second -leacsl -leacsl-gmp -leacsl -jemalloc -lpthread -lm
monitored_second.c:10:1: warning: ‘__FC_BUILTIN__’ attribute directive ignored [-Wattributes]
typedef __e_acsl_mpz_struct ( __attribute__((__FC_BUILTIN__)) __e_acsl_mpz_t)[1];
monitored_second.c:18:55: warning: ‘__FC_BUILTIN__’ attribute directive ignored [-Wattributes]
int line);
^
monitored_second.c:25:60: warning: ‘__FC_BUILTIN__’ attribute directive ignored [-Wattributes]
size_t ptr_size);
^
/usr/bin/ld: cannot find -leacsl
/usr/bin/ld: cannot find -leacsl-jemalloc
collect2: error: ld returned 1 exit status
I've also removed the "-rtl-bittree" label because it returns another error.
Frama-C version is the latest: Sulfur-20171101
Got any idea of what is happening?
Thanks!
Normally, you should have a script called e-acsl-gcc.sh installed in the same directory as frama-c binary, that can take care of calling gcc with appropriate options. Its basic usage is documented in section 2.2 of the manual, and man e-acsl-gcc.sh gives more details on the options that can be used. In short, you should be able to type
e-acsl-gcc.sh -c \
--oexec-eacsl=first_monitored \
--oexec=first \
--ocode=first_monitored.i \
first.i
to obtain
an executable first_monitored with the e-acsl instrumentation
an executable first with the original program
a source file first_monitored.i with the e-acsl generated C code
Edit Looking at the linking command used by the script, I'd say that the command line proposed earlier in the manual is out of date (in particular, it refers to eacsl-jemalloc whereas e-acsl-gcc.sh seems to prefer eacsl-dlmalloc), which could probably be reported as a bug at https://bts.frama-c.com

What is wrong with foreach in Qt?

Well, I tried it all. This should be very simple, yet I am stock at finding out what in the world is going on with my foreach. It just don't help.
#include <QCoreApplication>
//coreapplication or Qapplication the error is there
#include <QList>
#include <QDebug>
int main()
{
QList<int> list;
list << 1 << 2 << 3 << 4 << 5;
foreach (int i, list) //expected token ';' got 'int'.
{
qDebug() << i;
}
}
/*
QT += core gui
TARGET = QtTest
CONFIG += console
CONFIG -= app_bundle
CONFIG += no_keywords
TEMPLATE = app
SOURCES += main.cpp
*/
You specified no_keywords in your config. You have to use Q_FOREACH instead of foreach. See the documentation for foreach.
That being said, I would switch to the C++11 range-based for, since it doesn't have issues with commas in types. For example,
Q_FOREACH (QPair<int, int> p, pairList)
won't compile since the preprocessor thinks you're trying to invoke the macro with 3 arguments instead of 2.
Instead you can use the C++11 for(:):
for(int i:list)
{
qDebug() << i;
}
Note that you will have to compile with the C++-11 flag, therefore add this line to your project file:
QMAKE_CXXFLAGS += -std=c++11
Note that the C++11 for is more efficient than the Qt foreach as indicated by: Qt foreach loop ordering vs. for loop for QList
Edit:
Like commented by Frank Osterfeld you can also use:
CONFIG+=c++11
in your .pro file since Qt 5.4 as commented here: How to use C++11 in your Qt Projects.

Compiling and Linking KISSFFT

I have a newb problem with compiling and linking the kissfft library 'out of the box'. I've downloaded the kissfft library and extracted it to a test directory. Upon entering the directory and running 'make testall' I get the following errors, which look like the std c math library is not being linked to properly.
sharkllama#quaaludes:~/KISSFFT/kiss_fft129$ make testall
# The simd and int32_t types may or may not work on your machine
make -C test DATATYPE=simd CFLAGADD="" test
make[1]: Entering directory `/home/sharkllama/KISSFFT/kiss_fft129/test'
cd ../tools && make all
make[2]: Entering directory `/home/sharkllama/KISSFFT/kiss_fft129/tools'
cc -o fft_simd -Wall -O3 -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Waggregate-return -Wcast-align -Wcast-qual -Wnested-externs -Wshadow -Wbad-function-cast -Wwrite-strings -I.. -DUSE_SIMD=1 -msse -lm ../kiss_fft.c fftutil.c kiss_fftnd.c kiss_fftr.c kiss_fftndr.c
/tmp/ccFbS0yK.o: In function `kiss_fft_alloc':
kiss_fft.c:(.text+0xd17): undefined reference to `sincos'
kiss_fft.c:(.text+0xd6b): undefined reference to `floor'
kiss_fft.c:(.text+0xe07): undefined reference to `sincos'
kiss_fft.c:(.text+0xeba): undefined reference to `sqrt'
/tmp/ccbYqDcf.o: In function `kiss_fftr_alloc':
kiss_fftr.c:(.text+0x118): undefined reference to `sincos'
kiss_fftr.c:(.text+0x188): undefined reference to `sincos'
collect2: ld returned 1 exit status
make[2]: *** [fft_simd] Error 1
make[2]: Leaving directory `/home/sharkllama/KISSFFT/kiss_fft129/tools'
make[1]: *** [tools] Error 2
make[1]: Leaving directory `/home/sharkllama/KISSFFT/kiss_fft129/test'
make: *** [testall] Error 2
sharkllama#quaaludes:~/KISSFFT/kiss_fft129$
Clearly, the makefile is trying to link to the math library as the -lm option has been included. Can't make any sense of this. I've compiled numerous programs that properly link to the math library before. Any help would be appreciated.
Thanks,
-B
Kissfft is not really something you need to make and install like other libraries. If you need complex ffts, then all you need to do is compile the kiss_fft.c in your project. If you need something more specialized like multidimensional or real ffts, then you should also compile the apropriate file(s) from the tools dir.
The make targets are largely for development testing of kissfft. There are a lot of system requirements to do that testing. Unless you are changing the internals of kissfft, you won't need to use those testing targets.
Just wanted to share a practical example on how to build a simple application using 1D FFT/IFFT from kissfft:
g++ example.cpp -o example -I kissfft kissfft/kiss_fft.c
example.cpp:
#include "kissfft/kiss_fft.h"
int main()
{
// initialize input data for FFT
float input[] = { 11.0f, 3.0f, 4.05f, 9.0f, 10.3f, 8.0f, 4.934f, 5.11f };
int nfft = sizeof(input) / sizeof(float); // nfft = 8
// allocate input/output 1D arrays
kiss_fft_cpx* cin = new kiss_fft_cpx[nfft];
kiss_fft_cpx* cout = new kiss_fft_cpx[nfft];
// initialize data storage
memset(cin, 0, nfft * sizeof(kiss_fft_cpx));
memset(cout, 0, nfft * sizeof(kiss_fft_cpx));
// copy the input array to cin
for (int i = 0; i < nfft; ++i)
{
cin[i].r = input[i];
}
// setup the size and type of FFT: forward
bool is_inverse_fft = false;
kiss_fft_cfg cfg_f = kiss_fft_alloc(nfft, is_inverse_fft, 0, 0); // typedef: struct kiss_fft_state*
// execute transform for 1D
kiss_fft(cfg_f, cin , cout);
// transformed: DC is stored in cout[0].r and cout[0].i
printf("\nForward Transform:\n");
for (int i = 0; i < nfft; ++i)
{
printf("#%d %f %fj\n", i, cout[i].r, cout[i].i);
}
// setup the size and type of FFT: backward
is_inverse_fft = true;
kiss_fft_cfg cfg_i = kiss_fft_alloc(nfft, is_inverse_fft, 0, 0);
// execute the inverse transform for 1D
kiss_fft(cfg_i, cout, cin);
// original input data
printf("\nInverse Transform:\n");
for (int i = 0; i < nfft; ++i)
{
printf("#%d %f\n", i, cin[i].r / nfft); // div by N to scale data back to the original range
}
// release resources
kiss_fft_free(cfg_f);
kiss_fft_free(cfg_i);
delete[] cin;
delete[] cout;
return 0;
}
To use the 2D transforms, include the appropriate header "kissfft/tools/kiss_fftnd.h" and adjust the build command to:
g++ example.cpp -o example -I kissfft kissfft/kiss_fft.c kissfft/tools/kiss_fftnd.c
Simple enough!

Qt 4.7.4: Is there a way to find out the status of CAPS LOCK?

I know there were earlier problems with this in < 4.7.4 Qt versions. has this been resolved?
I don't know any Qt solution.
However this code should work on both windows (not tested) and x11-based os (works on linux)
#include <X11/XKBlib.h>
#include <QX11Info>
bool capsOn()
{
#ifdef Q_WS_WIN // MS Windows version
return GetKeyState(VK_CAPITAL) == 1;
#elif Q_WS_X11 // X11 version
unsigned int n = 0;
Display *d = QX11Info::display();
XkbGetIndicatorState(d, XkbUseCoreKbd, &n);
return (n & 0x01) == 1;
#else
# error Platform not supported
#endif
}
On X11 don't forget to add -lX11 to LIBS in your qmake project file.
I don't exactly know how to do this on OS X. If you need it, take a look at IOHIKeyboard and its's alphaLock() function. Also check this, especially the function darwinQueryHIDModifiers.

Resources