環境構築 Mac or Ubuntu
環境について
開発環境を整えます。
僕はWindowsはあまり触ったことないのと、そもそもパソコン5台(Macbook, MacbookPro, 自作Ubuntu, ラズパイ2台)も持ってるのにWindowsを持ってません。学校でもUbuntuしか使いません。
よって、Windowsの方は開発環境はなんとかしてください。多分大丈夫です。
Mac か Ubuntuを想定して書きます。あと、言語はCとC++とfortranとpython全部で書こうかと思います。数値解析のプログラムだとどれも対して変わらないので、やりたい言語でやっていただけるのが一番かと思いますが、僕はC++を推してます。
数値解析は速い言語で書くのが一般的なので、基本はCやC++かfortranで書かれていることが多いです。ただ、pythonは分かりやすいし勉強しやすいのでありかと思います。pythonも別にそこまで遅くなく、そもそもCで書かれたライブラリをほぼ使うし、最適化されているのでむしろ一部分だけ見ると速い可能性もあります。
fortranは過去のコードを読むためにも必要だし、pythonは理解や試行錯誤しやすいんですが、C++は僕が好きなオープンソースの数値解析ソフトOpenFOAMがC++なのと、freefem++というC++ベースの言語を使ったりするので、C++を推してます。とりあえず、メインはC++で書いて、Cやfortran 2008、pythonで書き直したものはgithubに上げて行こうかと思います。
C++とFortranとgnuplotの環境構築
C++(C)とFortranの環境構築をします。
Macの方はHomebrewを入れます。
xcodeを入れてない方はAppstoreからxcodeを入れるか、xcodeの必要な部分だけを以下のコマンドでインストールします。
1 |
xcode-select --install |
そしたら、Homebrewのサイトからコマンドをコピペして、実行してください。
次に、CとC++fortranのコンパイラを入れます。どれもgccに入っているので、gccをインストールします。
1 |
brew install gcc |
ここから、最新版にアップデートします。
Homebrew経由で入れたパッケージは/usr/local/Celler/に保存され、/usr/local/bin/にコマンドのエイリアスが自動で貼られます。
/usr/local/bin/からエイリアスを探し当てます
1 2 |
ls /usr/local/bin | grep gcc ls /usr/local/bin | grep g++ |
上記コマンドで見つかったgcc-9とg++-9などの最新版がお目当てのエイリアスです。
見つかったエイリアスに対してシンボリックリンクを貼ります。
1 2 |
ln -s /usr/local/bin/gcc-9 /usr/local/bin/gcc ln -s /usr/local/bin/g++-9 /usr/local/bin/g++ |
最後に~/.bash_profileの良い感じの場所に以下の記述をして、優先順位高めのパスを通したら終了です。
1 |
export PATH=$PATH:/usr/local/bin |
ver確認してみます。
1 2 |
gcc --version g++ --version |
これでgcc,g++,gfortranのインストールは終わりです。
続いて、gnuplotをインストールします。gnuplotだけをインストールしてもうまく画面表示してくれないので、aquatermとx11をまずインストールします。
- AquaTermのインストール
AquaTermのダウンロードページより、ダウンロードしてインストール。
- X11のインストール
Mac用の X11ライブラリ XQuartz のダウンロードページより、ダウンロードしてインストール。
1 2 |
brew uninstall gnuplot #既にインストールしている場合アンインストール brew install gnuplot --with-aquaterm --with-x11 |
これでできるはずですが、(2019/10/01)時点ではエラーがでる模様です。
その場合は、一旦素でインストールして、一旦バックアップをとります。
1 2 |
brew install gnuplot sudo cp /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/gnuplot.rb /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/gnuplot_backup.rb |
何かしらのエディタで開きます。
1 |
vi /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/gnuplot.rb |
内容を全て以下の内容に書き換えます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
class Gnuplot < Formula desc "Command-driven, interactive function plotting" homepage "http://www.gnuplot.info/" url "https://downloads.sourceforge.net/project/gnuplot/gnuplot/5.2.6/gnuplot-5.2.6.tar.gz" sha256 "35dd8f013139e31b3028fac280ee12d4b1346d9bb5c501586d1b5a04ae7a94ee" revision 1 bottle do rebuild 1 sha256 "47903eca8637b8de9b803932795fe9dec4a45df4ea8ab61c51e2692501edce03" => :mojave sha256 "24a6c735fb69f8f7f016cf4ecadbe8d11022523c9d7160ef03160f41bf117aa7" => :high_sierra sha256 "5ef8fe2bebfcc2232f8ee414f0ce0c6b13482e212938d041dc55db7ea139eb10" => :sierra end head do url "https://git.code.sf.net/p/gnuplot/gnuplot-main.git" depends_on "autoconf" => :build depends_on "automake" => :build depends_on "libtool" => :build end option "with-aquaterm", "Build with AquaTerm support" option "with-wxmac", "Build with wxmac support" deprecated_option "qt" => "with-qt" deprecated_option "with-qt5" => "with-qt" deprecated_option "with-x" => "with-x11" deprecated_option "wx" => "with-wxmac" depends_on "pkg-config" => :build depends_on "gd" depends_on "lua" depends_on "pango" depends_on "readline" depends_on "qt" => :optional depends_on "wxmac" => :optional depends_on :x11 => :optional needs :cxx11 if build.with? "qt" resource "libcerf" do url "http://apps.jcns.fz-juelich.de/src/libcerf/libcerf-1.5.tgz" mirror "https://www.mirrorservice.org/sites/distfiles.macports.org/libcerf/libcerf-1.5.tgz" sha256 "e36dc147e7fff81143074a21550c259b5aac1b99fc314fc0ae33294231ca5c86" end def install # Qt5 requires c++11 (and the other backends do not care) ENV.cxx11 if build.with? "qt" if build.with? "aquaterm" # Add "/Library/Frameworks" to the default framework search path, so that an # installed AquaTerm framework can be found. Brew does not add this path # when building against an SDK (Nov 2013). ENV.prepend "CPPFLAGS", "-F/Library/Frameworks" ENV.prepend "LDFLAGS", "-F/Library/Frameworks" end # gnuplot is not yet compatible with More recent libcerf: # https://sourceforge.net/p/gnuplot/bugs/2077/ # In next release, we can remove this and depend on the libcerf formula. resource("libcerf").stage do system "./configure", "--prefix=#{buildpath}/libcerf", "--enable-static", "--disable-shared" system "make", "install" end ENV.prepend_path "PKG_CONFIG_PATH", buildpath/"libcerf/lib/pkgconfig" args = %W[ --disable-dependency-tracking --disable-silent-rules --prefix=#{prefix} --with-readline=#{Formula["readline"].opt_prefix} --without-tutorial ] args << "--disable-wxwidgets" if build.without? "wxmac" args << (build.with?("aquaterm") ? "--with-aquaterm" : "--without-aquaterm") args << (build.with?("qt") ? "--with-qt" : "--with-qt=no") args << (build.with?("x11") ? "--with-x" : "--without-x") system "./prepare" if build.head? system "./configure", *args ENV.deparallelize # or else emacs tries to edit the same file with two threads system "make" system "make", "install" end def caveats if build.with? "aquaterm" <<~EOS AquaTerm support will only be built into Gnuplot if the standard AquaTerm package from SourceForge has already been installed onto your system. If you subsequently remove AquaTerm, you will need to uninstall and then reinstall Gnuplot. EOS end end test do system "#{bin}/gnuplot", "-e", <<~EOS set terminal dumb; set output "#{testpath}/graph.txt"; plot sin(x); EOS assert_predicate testpath/"graph.txt", :exist? end end |
そして、gnuplotをアンインストールしてから、再度入れます。
1 2 |
brew uninstall gnuplot brew install gnuplot --with-aquaterm --with-x11 |
これで完了です。
ubuntuの場合は、
Pythonの環境構築
とりあえず、pyenvという開発環境を複数入れれるやつを入れて、そこからanacondaをインストールします。anacondaは最初から数値解析等に必要なパッケージが入ってるやつです。便利。
1 |
apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev libpng-dev |
1 2 3 4 5 6 |
git clone git://github.com/yyuu/pyenv.git ~/.pyenv git clone https://github.com/yyuu/pyenv-pip-rehash.git ~/.pyenv/plugins/pyenv-pip-rehash echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc echo 'eval "$(pyenv init -)"' >> ~/.bashrc source ~/.bashrc |
1 |
pyenv install --list |
1 |
pyenv install anaconda3-5.3.1 |
1 |
pyenv global anaconda3-5.3.1 |
1 |
(anadonda3-5.3.1)Macbook-8:tryeting1800002.1$ |
1 |
export PYENV_VIRTUALENV_DISABLE_PROMPT=1 |
1 |
vi ~/.bash_profile |
ディスカッション
コメント一覧
まだ、コメントがありません