Whats wrong with
什么毛病
for (level = 1; level <= log2((double)size); level++)
^
Seems like its from using log2()
but whats wrong? I am using it with OpenMPI code actually, but commenting this line fixes things.
似乎是使用log2(),但什么是错的?实际上,我使用的是OpenMPI代码,但是注释这一行可以修复问题。
Full Source(http://pastie.org/7559178) see line 40
完整的源代码(http://pastie.org/7559178)见第40行。
[jiewmeng@JM Assign3]$ mpicc -o cpi cpi.c && mpirun -np 16 cpi
/usr/bin/ld: /tmp/cca9x4he.o: undefined reference to symbol 'log2@@GLIBC_2.2.5'
/usr/bin/ld: note: 'log2@@GLIBC_2.2.5' is defined in DSO /usr/lib/libm.so.6 so try adding it to the linker command line
/usr/lib/libm.so.6: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
Seems like log2(4)
will work but I cant pass in a variable?
看起来log2(4)会起作用,但我不能传递变量?
1 个解决方案
#1
28
In in order to link libm
you need to add -lm
argument, as this document; MPI under Linux in the Math Department says:
为了链接libm,需要添加-lm参数,作为这个文档;MPI在Linux下的数学部门说:
If your code includes mathematical functions (like exp, cos, etc.), you need to link to the mathematics library libm.so. This is done, just like for serial compiling, by adding -lm to the end of your compile command, that is,
如果您的代码包含数学函数(如exp、cos等),则需要链接到数学库libm.so。这就完成了,就像串行编译一样,通过将-lm添加到编译命令的末尾,也就是说,
mpicc -o sample sample.c -lm
mpicc - o示例样本。c - lm
#1
28
In in order to link libm
you need to add -lm
argument, as this document; MPI under Linux in the Math Department says:
为了链接libm,需要添加-lm参数,作为这个文档;MPI在Linux下的数学部门说:
If your code includes mathematical functions (like exp, cos, etc.), you need to link to the mathematics library libm.so. This is done, just like for serial compiling, by adding -lm to the end of your compile command, that is,
如果您的代码包含数学函数(如exp、cos等),则需要链接到数学库libm.so。这就完成了,就像串行编译一样,通过将-lm添加到编译命令的末尾,也就是说,
mpicc -o sample sample.c -lm
mpicc - o示例样本。c - lm