LoginSignup
4
0

More than 1 year has passed since last update.

「「FORTRAN77数値計算プログラミング」のプログラムをCとPython」をdockerで

Last updated at Posted at 2019-08-27

「FORTRAN77数値計算プログラミング」のプログラムをCとPythonに移植してみる(その1)
https://qiita.com/riko111/items/084b774327c716044b13

をdocker上で動かし、確認したので記録する。

<この項は書きかけです。順次追記します。>

ソースコードの先頭には、上記URLを註記(commnet)している。

$ docker run -it kaizenjapan/ncpfcp /bin/bash

作成したフォルダは /home/ncp
ncp: numerical calculation programming
tcp: fortran c_language python

作成したscriptは、

ncp.sh
#!/bin/sh
# (c) @kaizen_nagoya
echo "https://qiita.com/riko111/items/084b774327c716044b13"
echo "$ clang $1.c"
cc $1.c -o $1cl 
if [  -e $1cl ]; then
./$1cl 
fi
echo "\r"
echo "$ gcc $1.c"
gcc $1.c -o $1cg 
if [  -e $1cg ]; then
./$1cg 
fi
echo "$ gfortran $1.f"
gfortran $1.f -o $1f 
if [  -e $1f ]; then
./$1f 
fi
echo "\r"
echo "$ python3 $1.py"
python3 $1.py
echo "\r"
echo "$ python2 $1.py"
python2 $1.py
gfortran --version
gcc --version
clang --version
python3 --version
python2 --version

-O3 option をつけたものは

ncpO3.sh
#!/bin/sh
# (c) @kaizen_nagoya
echo "https://qiita.com/riko111/items/084b774327c716044b13"
echo "$ clang $1.c"
cc $1.c -O3 -o $1clO3 
if [  -e $1clO3 ]; then
./$1clO3 
fi
echo "\r"
echo "$ gcc $1.c"
gcc $1.c -O3 -o $1cgO3
if [  -e $1cgO3 ]; then
./$1cgO3 
fi
echo "$ gfortran $1.f"
gfortran $1.f -O3 -o $1fO3 
if [  -e $1fO3 ]; then
./$1fO3 
fi
echo "\r"
echo "$ python3 $1.py"
python3 $1.py
echo "\r"
echo "$ python2 $1.py"
python2 $1.py

ソースとこのスクリプトを含み、gfortran, gcc, clang, python2, python3が実行できる環境は、

$ docker run -v /Users/administrator/work:/home/work -it kaizenjapan/ncpfcp /bin/bash

でフォルダ共有して利用できる。ただし、/Users/asministrator/workは実際に存在するフォルダ名。

docker/ubuntu
# cd /home/ncp
# ./ncp.sh maceps
https://qiita.com/riko111/items/084b774327c716044b13
$ clang maceps.c
1.19209290E-07
1.19209290E-07

$ gcc maceps.c
1.19209290E-07
1.19209290E-07
$ gfortran maceps.f
   1.19209290E-07

$ python3 maceps.py
1.19209290E-07
1.19209290E-07

$ python2 maceps.py
1.19209290E-07
1.19209290E-07
GNU Fortran (GCC) 9.1.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

gcc (GCC) 9.1.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

clang version 7.0.1-8 (tags/RELEASE_701/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Python 3.7.3
Python 2.7.16

一方のスクリプトは、最後に言語の版を出力しています。
結果がわかるように。
C言語のプログラムだけ

meceps.c
#include <stdlib.h>
...
    return EXIT_SUCCESS;
}

stdlibをincludeし、returnの値をEXIT_SUCCESSに変更している。

これは直値を書かないという自分の仕事上の規則によるものです。万人に推めているものではありません。
OSにより戻り値が意味がない場合もあり、OSの宣言に任せるという趣旨です。

<この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。>

文書履歴(document history)

ver. 0.01 初稿 20190827

このエントリーをはてなブックマークに追加
https://b.hatena.ne.jp/guide/bbutton

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0