快速,轻松的安装和安装在Linux/Windows上使用IT ++库? [英] Quick and Hassle-free Installation & Usage of IT++ library on Linux/Windows?

查看:112
本文介绍了快速,轻松的安装和安装在Linux/Windows上使用IT ++库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IT ++ 是流行的GPL库(

IT++ is a popular GPL library (proposed to be LGPL but no signs as of now) for scientific computation especially in Telecommunications domain. This was recommended to me by my colleagues.

在我的Linux/Windows系统上安装此库似乎很困难.而且安装指南似乎很难.

It looks hard to install this piece of library on my Linux/Windows system. And the installation guide seems hard.

除了花时间进行此安装外,我还有很多事情要做.有人可以通过快速安装以及一些你好,世界!输入说明来节省我一些时间吗?

I have a lot more to do other than spending time on this installation. Can anyone save me some time with a few quick installation and if possible, some hello, world! type instructions?

推荐答案

TL; DR

 $ wget https://sourceforge.net/projects/itpp/files/latest -O itpp.tar.bz2
 $ tar -xjvf itpp.tar.bz2 && cd itpp-*
 $ sudo apt-get install liblapack-dev libblas-dev libfftw3-dev
                 # Note: This is basic and recommended. MKL/ATLAS etc are
                 # platform-specialized, can give slightly better perf.

 $ mkdir build1 build2

 $ cd build1                   # DYNAMIC (*.so file)  
 $ cmake ..  
 $ make  
 $ make install  

 $ cd bulid2                   # STATIC (*.a file)
 $ cmake .. -DITPP_SHARED_LIB=off
 $ make
 $ make install

 # Note: The library installation is complete and is ready for both
 # static and dynamic compilations. But the subsequent run of a 
 # *static compilation* is relatively more difficult, see details below.

INTRO

IT ++是一个功能强大的数值计算库,在通讯理论领域的研究人员中颇受欢迎,它提供与矩阵有关的构造. 尽管其他矩阵库(相对较新的Eigen等)越来越受欢迎,但与MATLAB相比,它的美观和优美的界面仍在使用.它还通过Mex例程提供了与MATLAB的接口.我一直都在用它.

INTRO

IT++, is a powerful numerical computing library popular among researchers working in communication theory, providing matrix related constructs. While other matrix libraries relatively recent Eigen etc are gaining more popularity, it remains in use for its beautiful and elegant interface usually compared to MATLAB. It also provides interfacing to MATLAB via Mex routines. I use it all the time.

不幸的是,即使安装说明看起来已经足够完整,在我自己的同事中,初学者感到非常痛苦.我认为这是因为它不适合初学者.我衷心希望这篇文章能弥合差距.

Unfortunately, even though the installation instructions appear sufficiently complete, it is very painful for beginners as I find among my own colleagues. The reason I think is that it is not beginner-friendly. I sincerely hope this post will bridge the gap.

我认为安装中的主要困惑是由于其对BLAS,LAPACK和FFTW的依赖性,在可选,BLAS/LAPACK的特定于供应商的版本中提到/FFTW(例如MKL,ATLAS,ACML库)增加了实际操作的混乱.

I think the main source of confusion in the installation is due to its dependencies of BLAS, LAPACK, and FFTW, being mentioned along-side of the optional, vendor-specific versions of BLAS/LAPACK/FFTW such as MKL, ATLAS, ACML libraries adding to the confusion of what actually is to be done.

事实是,大多数令人困惑的位是可选的!

The fact is, a majority of those confusing bits are optional!

我建议先尝试以下快速说明,然后再忽略其他所有内容.

I would recommend to first try the below quick instructions and ignore everything else till then.

  1. 下载IT ++存档文件
    $ wget https://sourceforge.net/projects/itpp/files/latest -O itpp.tar.bz2

  1. Download IT++ archive file
    $ wget https://sourceforge.net/projects/itpp/files/latest -O itpp.tar.bz2

提取并更改目录
$ tar -xjvf itpp.tar.bz2 && cd itpp-*

Extract and change directory
$ tar -xjvf itpp.tar.bz2 && cd itpp-*

创建新的子目录"build1"和"build2"(在接下来的步骤中,我们将对它们进行cd) $ mkdir build1 build2

Create new sub-directories "build1" and "build2" (we will cd to them in next steps) $ mkdir build1 build2

确保您具有LAPACK,BLAS,FFTW库.顺便说一句,这不会影响以后的阶段.
$ sudo apt-get install liblapack-dev libblas-dev libfftw3-dev

Make sure you have LAPACK, BLAS, FFTW libraries. This should not affect later stages btw.
$ sudo apt-get install liblapack-dev libblas-dev libfftw3-dev

这是一个重要的警告:通常,更有效的选择是使用处理器的供应商特定的库,例如 AMD的ACML ATLAS .但是这种效率是有代价的-您需要花费大量时间来注册(对于MKL),下载,安装并最终调整链接器开关,使其在每次编译和运行时都包括它们.

Here an important caveat: A more efficient option is often said to be to use your processor's vendor-specific library such as Intel's MKL, AMD's ACML, ATLAS. But that efficiency comes at a cost -- you need to spend significant time to register (for MKL), download, install, and finally adjust linker switches to include them every time they are compiled and run.

  1. 主要安装步骤:
    同时执行两个步骤.没有什么坏处,再加上我个人认为IT ++应该同时安装这两个组件作为默认选项.仅仅是因为,您永远都不知道将来什么时候需要静态编译.这就是为什么几乎所有其他库都在您的PC上同时安装这两个版本的原因.

  1. The main installation steps:
    Please do both steps below. There is no harm, plus I personally think IT++ should have installing both as the default option. Simply because, you never know when do you require a static compilation in future. This is why almost every other library installs both versions on your pc.

A. 作为共享库 (*.so文件)

A. As a shared library (*.so files)

  $ cd build1  
  $ cmake ..  
  $ make  
  $ make install  

B. 作为静态库 (*.a个文件)

B. As a static library (*.a files)

  $ cd bulid2
  $ cmake .. -DITPP_SHARED_LIB=off
  $ make
  $ make install

在cmake期间,您可能会遇到以下错误,但是在成功运行单个IT ++程序之前,它们不会影响以后的阶段.因此,请忽略它们.将来,更高版本可能会声明/更正它们为错误.当前版本是4.3.1.

During cmake, you might experience the below errors, but they never affected later stages till successful running of individual IT++ programs. So please ignore them. In future, later versions might declare/correct them as bugs. Current version is 4.3.1.

     CMake Warning at CMakeLists.txt:192 (message):
        BLAS library not found.

     CMake Warning at CMakeLists.txt:196 (message):
        LAPACK library not found.

     CMake Warning at CMakeLists.txt:200 (message):
        FFT library not found.

使用Hello,World测试您的安装!

请考虑以下示例程序testITPP.cpp

  #include<iostream>
  using namespace std;
  #include<itpp/itbase.h>
  using namespace itpp;

  int main()
  {
    vec x(100); // vec == Vec<double>
    double y;
    x=linspace(1,100,100);
    y=sum(x);
    cout<<"Hello, World! \n The sum of first 100 integers is: "<<y<<endl;
  }

现在,编译期间最重要的事情是在所有文件之后,始终使用-litpp开关.

Now the main important thing during compilation is to use -litpp switch all the time, after all the files.

$ g++ testITPP.cpp -litpp
$./a.out 
Hello, World! 
The sum of first 100 integers is: 5050

如果./a.out产生错误,请运行一次sudo ldconfig刷新库缓存.

If ./a.out produces errors, please run sudo ldconfig once to refresh library cache.

请注意,较早的编译默认情况下使用共享库并生成一个二进制文件,该二进制文件取决于您PC上的其他二进制文件太多.也就是说,上面的二进制a.out无法在没有安装IT ++的另一个Unix系统上运行,例如这通常会带来问题,尤其是在提交给大学集群和服务器的过程中,这些问题使用户可以执行繁重且长时间的计算.

Note that the earlier compilation uses shared-libraries by default and produces a binary that depends on too many other binaries on your PC. I.e., the above binary a.out cannot run on another unix system with no IT++ installed for e.g. This often creates problems, especially during submissions to university clusters and servers which allow users to perform heavy and long-duration computations.

一种解决方法是使用静态编译,摆脱所有本地依赖关系.但这对于初学者通常很困难.使用MKL类库下的IT ++,仅知道如何进行静态编译确实令人沮丧.有关如何做的一个很好的总结,以及我今天注意到的所有错误,如下所示.

A work-around is to use a static compilation, getting rid of all local dependencies. But this is usually difficult for beginners. With IT++ under MKL kind of libraries, it can really be frustrating to just know how to static-compile. A good summary of how to do plus all the bugs that I notice as of today are as below.

这是最简单的情况.需要注意两个特别重要的变化.一个-litpp变为-litpp_static.二,新的编译开关-static.首先是IT ++奇怪地选择将二进制文件命名为libitpp.so和libitpp_static.a的结果.

This is the simplest case. Two particularly important changes are to be noted. One -litpp becomes -litpp_static. Two, the new compilation switch -static. The first is a result of IT++'s strange choice to name binaries as libitpp.so and libitpp_static.a.

此外,与动态编译不同,对于静态编译,可能必须包括除C ++标准库(即-lc和-lm)以外的所有库.主要包括-lblas -llapack -lfftw -lpthread-ldl.

Also, unlike dynamic compilation, it may be compulsary to include all libraries other than C++ standard ones (i.e. -lc and -lm) for static compilation. This mainly includes -lblas -llapack -lfftw -lpthread and -ldl.

因此,以下情况之一可能适用于您的情况:

As a result, one of the following might work in your case:

$ g++ -static testITPP.cpp -litpp_static
 OR
$ g++ -static testITPP.cpp -litpp_static -llapack -lblas -lpthread
 OR
$ g++ sctest_PCCestimates.cpp -litpp_static \
       -llapack -lblas -lgomp -lpthread \
       -lgfortran -static -Wl,--allow-multiple-definition 

ii.使用MKL的BLAS/LAPACK/FFTW进行静态编译:

虽然我还没有看到使用MKL的特定于供应商的库有多快,但是静态编译确实非常痛苦. MKL本身的初始安装花了我一个多小时.即使确切的说明不适合其他供应商库,它也应该使您为即将面临的实际挑战做好准备.

ii. Static compilation with MKL's BLAS/LAPACK/FFTW:

While I am yet to see how faster it is to use MKL's vendor-specific libraries, the static compilation can be really painful. The initial installation of MKL itself took more than an hour to me. Even though the exact instructions won't fit for other vendor-libraries, it should get you ready for the actual challenges you are about to face.

您遇到的错误消息无法理解以下大多数内容.结果,它们将非常烦人并且难以解决.我正在尝试将它们全部列在下面.希望他们可以节省您大量的宝贵时间.

Most of the below are not understood by the error messages that you encounter. As a result they will be very annoying and painful-to-resolve. I am trying to list them all below. Hopefully they will save a ton of your valuable time.

  1. 编译期间的循环依赖性:前几个库可能需要用-Wl,--start-group .... -Wl,--end-group包围.

使用特定于供应商的blas/lapack/fftw,您可能需要在特定于供应商的库中搜索它们各自的libblas.a liblapack.a libfftw.a或类似的内容(例如libmkl_core.a).必须使用开关-L/path/to/statics/

With vendor-specific blas/lapack/fftw, you may need to search where their respective libblas.a liblapack.a libfftw.a or their equivalents such as libmkl_core.a in your vendor-specific library. The directory location must be supplied using the switch -L/path/to/statics/

即使成功编译后,也可能会遇到segmentation fault.造成此烦人问题的原因似乎是libpthread.a并未完全包含在内.然后,通过将开关-lpthread包围为-Wl,--whole-archive -lpthread -Wl,--no-whole-archive

A segmentation fault may be encountered, even after a successful compilation. The reason for this annoying problem seems to be that the libpthread.a is not entirely included. Then you need force appropriate action, by surrounding the switch -lpthread as -Wl,--whole-archive -lpthread -Wl,--no-whole-archive

最后,在Ubuntu 16.04上对我有用的版本是这个.请注意,没有-llapack -lblas -lfftw等内容,因为它们捆绑在不同名称的静态二进制文件下.

Finally the version that worked to me on Ubuntu 16.04 is this. Note that there is none of -llapack -lblas -lfftw etc, as they are bundled under differently named static binaries.

$ g++ -static \  
        -L/opt/intel/compilers_and_libraries/linux/mkl/lib/intel64_lin/  
       testITPP.cpp  
        -Wl,--start-group \
        -litpp_static \
        -lmkl_intel_lp64 \
        -lmkl_sequential \
        -lmkl_core  -Wl,--end-group \
        -Wl,--whole-archive -lpthread -Wl,--no-whole-archive \
        -ldl

最后,尽管您已经在上面成功生成了一个静态二进制文件,但是您可能会得到一条警告,提示warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking可能会出现,但是可以被忽略,因为显然没有解决方案!这与我们无需关心的普遍已知问题有关.

Finally, inspite of you having a static binary successfully generated in above, you might get a warning saying warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking might appear but can be ignored as apparently there is no solution ever! This is related to a universally known issue that we need not care.

希望其他人会编写Windows/Visual-Studio安装指南.

Hoping that someone else will write a guide for Windows/Visual-Studio installation.

这篇关于快速,轻松的安装和安装在Linux/Windows上使用IT ++库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆