コンテンツにスキップ

Trial of OpenSWPC

Google Colaboratory is a cloud-based Python platform provided by Google Research. Since the Google Colaboratory is working under Ubuntu Linux, we can compile and try to execute small examples of the OpenSWPC without preparing physical Linux server on your office. Computing in this cloud environment is a perfect demonstration to get an overview of OpenSWPC.

This document file is created under the Google Colaboratory, and converted to HTML as a part of the user's guide.

First, let us confirm that Google Colaboratory is working under ubuntu. Any linux commands can be executed in the Jupyter notebook by prepending ! before the command:

1
! uname -a
1
Linux 814eb6f6abe0 5.10.133+ #1 SMP Fri Aug 26 08:44:51 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
1
! cat /etc/os-release
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
NAME="Ubuntu"
VERSION="18.04.6 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.6 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

Python preparation

The following Python code is to display Mpeg-4 videos. Reference: https://qiita.com/jun40vn/items/ace7758cd0522f2904de

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
from IPython.display import HTML
from base64 import b64encode

def show_mp4(mp4file):
  mp4 = open(mp4file, 'rb').read()
  data_url = 'data:video/mp4;base64,' + b64encode(mp4).decode()

  html=HTML(f"""
<video width="50%" height="50%" controls>
   <source src="{data_url}" type="video/mp4">
</video>""")

  return html

Download & Compile OpenSWPC

In ubuntu linux, we usually use apt command to install packages. OpenSWPC depends on the NetCDF libraries for input/output, so we need libnetcdf-dev and libnetcdff-dev packages. The latter is the fortran interface of the NetCDF.

1
! apt install libnetcdf-dev libnetcdff-dev
 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
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libnetcdf-dev is already the newest version (1:4.6.0-2build1).
libnetcdf-dev set to manually installed.
The following package was automatically installed and is no longer required:
  libnvidia-common-460
Use 'apt autoremove' to remove it.
Suggested packages:
  netcdf-bin netcdf-doc
The following NEW packages will be installed:
  libnetcdff-dev libnetcdff6
0 upgraded, 2 newly installed, 0 to remove and 7 not upgraded.
Need to get 368 kB of archives.
After this operation, 1,449 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu bionic/universe amd64 libnetcdff6 amd64 4.4.4+ds-3 [92.7 kB]
Get:2 http://archive.ubuntu.com/ubuntu bionic/universe amd64 libnetcdff-dev amd64 4.4.4+ds-3 [275 kB]
Fetched 368 kB in 1s (586 kB/s)
Selecting previously unselected package libnetcdff6.
(Reading database ... 124015 files and directories currently installed.)
Preparing to unpack .../libnetcdff6_4.4.4+ds-3_amd64.deb ...
Unpacking libnetcdff6 (4.4.4+ds-3) ...
Selecting previously unselected package libnetcdff-dev.
Preparing to unpack .../libnetcdff-dev_4.4.4+ds-3_amd64.deb ...
Unpacking libnetcdff-dev (4.4.4+ds-3) ...
Setting up libnetcdff6 (4.4.4+ds-3) ...
Setting up libnetcdff-dev (4.4.4+ds-3) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1.6) ...

Then, let us download and compile OpenSWPC:

1
! git clone https://github.com/tktmyd/OpenSWPC.git
1
2
3
4
5
6
7
Cloning into 'OpenSWPC'...
remote: Enumerating objects: 4041, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 4041 (delta 1), reused 1 (delta 0), pack-reused 4035
Receiving objects: 100% (4041/4041), 52.58 MiB | 35.05 MiB/s, done.
Resolving deltas: 100% (2747/2747), done.
1
! cd ./OpenSWPC/src; make arch=ubuntu-gfortran
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
cd swpc_3d;  make arch=ubuntu-gfortran
make[1]: Entering directory '/content/OpenSWPC/src/swpc_3d'
mpif90 -I/usr/include -D_NETCDF -O2 -ffast-math -D_INFO -I../include -fopenmp -o m_std.o    -c ../shared/m_std.F90
mpif90 -I/usr/include -D_NETCDF -O2 -ffast-math -D_INFO -I../include -fopenmp -o m_pdebug.o     -c ../shared/m_pdebug.F90
mpif90 -I/usr/include -D_NETCDF -O2 -ffast-math -D_INFO -I../include -fopenmp -o m_system.o     -c ../shared/m_system.F90
mpif90 -I/usr/include -D_NETCDF -O2 -ffast-math -D_INFO -I../include -fopenmp -o m_fdtool.o     -c ../shared/m_fdtool.F90
mpif90 -I/usr/include -D_NETCDF -O2 -ffast-math -D_INFO -I../include -fopenmp -o m_pwatch.o     -c ../shared/m_pwatch.F90
mpif90 -I/usr/include -D_NETCDF -O2 -ffast-math -D_INFO -I../include -fopenmp -o m_daytim.o     -c ../shared/m_daytim.F90
... 
(omitted below.)

After long messages, we get executable binaries under ./OpenSWPC/bin/ directory:

1
! ls ./OpenSWPC/bin
1
2
3
4
diff_snp.x    gen_rmed3d.x   mapregion.x   swpc_psv.x      wav2sac.x
fdmcond.x     grdsnp.x       qmodel_tau.x  swpc_sh.x       wvconv.x
fs2grd.x      ll2xy.x        read_snp.x    timvis_abs.gmt  xy2ll.x
gen_rmed2d.x  mapregion.gmt  swpc_3d.x     timvis.gmt

Execution

Unfortunatelly, the computational resouce freely available in the Google Colaboratory is limited. So we cannot execute 3D large numerical simulation of the production-level on this. Here, let us execute 2D P-SV example.

1
cd OpenSWPC
1
/content/OpenSWPC

To execute a code using MPI under the Google Colaboratory, we need --allow-run-as-root option.

1
! mpirun --allow-run-as-root -np 2 ./bin/swpc_psv.x -i example/input.inf
 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
 ------------------------------------------------------------------------------
  SWPC_PSV                                                                    
 ------------------------------------------------------------------------------


  Grid Size               :      384 x    384
  MPI Partitioning        :               2
  Total Memory Size       :           0.020  [GiB]
  Node Memory Size        :           0.010  [GiB]
  Stability  Condition c  :           0.526  (c<1)
  Wavelength Condition r  :          12.488  (r>5-10)
  Minimum velocity        :           3.122  [km/s]
  Maximum velocity        :           7.977  [km/s]
  Maximum frequency       :           0.500  [Hz]

 ------------------------------------------------------------------------------

  it=0000050, 0.065 s/loop, eta 000:01:01, ( 7.40E-02  2.73E-01 )
  it=0000100, 0.061 s/loop, eta 000:00:54, ( 8.13E-01  2.01E+00 )
  it=0000150, 0.062 s/loop, eta 000:00:52, ( 7.71E-01  1.46E+00 )
  it=0000200, 0.060 s/loop, eta 000:00:48, ( 2.90E-01  2.56E-01 )
  it=0000250, 0.059 s/loop, eta 000:00:44, ( 2.21E-01  3.03E-01 )
  it=0000300, 0.060 s/loop, eta 000:00:41, ( 1.90E-01  3.22E-01 )
  it=0000350, 0.058 s/loop, eta 000:00:37, ( 1.76E-01  3.27E-01 )
  it=0000400, 0.056 s/loop, eta 000:00:33, ( 1.93E-01  3.23E-01 )
  it=0000450, 0.055 s/loop, eta 000:00:30, ( 1.92E-01  3.08E-01 )
  it=0000500, 0.054 s/loop, eta 000:00:26, ( 1.89E-01  3.19E-01 )
  it=0000550, 0.054 s/loop, eta 000:00:24, ( 1.83E-01  3.33E-01 )
  it=0000600, 0.055 s/loop, eta 000:00:21, ( 1.75E-01  3.34E-01 )
  it=0000650, 0.055 s/loop, eta 000:00:19, ( 1.70E-01  3.36E-01 )
  it=0000700, 0.055 s/loop, eta 000:00:16, ( 1.69E-01  3.37E-01 )
  it=0000750, 0.055 s/loop, eta 000:00:13, ( 1.73E-01  3.48E-01 )
  it=0000800, 0.055 s/loop, eta 000:00:10, ( 1.76E-01  3.53E-01 )
  it=0000850, 0.055 s/loop, eta 000:00:08, ( 1.77E-01  3.45E-01 )
  it=0000900, 0.055 s/loop, eta 000:00:05, ( 1.81E-01  3.41E-01 )
  it=0000950, 0.055 s/loop, eta 000:00:02, ( 1.77E-01  3.39E-01 )
  it=0001000, 0.055 s/loop, eta 000:00:00, ( 1.63E-01  3.36E-01 )

 ------------------------------------------------------------------------------

  Total time             :          54.727 s

 ------------------------------------------------------------------------------
Note: The following floating-point exceptions are signalling: IEEE_UNDERFLOW_FLAG
Note: The following floating-point exceptions are signalling: IEEE_UNDERFLOW_FLAG

The warning messages regarding floating-point underflow do not matter.

Visualization

OpenSWPC also comes with dedicated tools for visualization.

1
! ./bin/read_snp.x -i out/swpc.xz.v.nc -ppm -pall -mul 10
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
 ppm/swpc.xz.v2.000000.ppm
 ppm/swpc.xz.v2.000001.ppm
 ppm/swpc.xz.v2.000002.ppm
 ppm/swpc.xz.v2.000003.ppm
 ppm/swpc.xz.v2.000004.ppm
 ppm/swpc.xz.v2.000005.ppm
 ppm/swpc.xz.v2.000006.ppm
 ppm/swpc.xz.v2.000007.ppm
 ppm/swpc.xz.v2.000008.ppm
 ppm/swpc.xz.v2.000009.ppm
 ppm/swpc.xz.v2.000010.ppm
 ...
 (omitted below)

Let us confirm the result as an animation movie by using ffmpeg.

1
! ffmpeg -i ppm/swpc.xz.v2.%6d.ppm -qscale 0 -pix_fmt yuv420p -y swpc.mp4
1
2
3
4
5
ffmpeg version 3.4.11-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  ...
  (omitted below)
1
show_mp4("./swpc.mp4")