Skip to content

Instantly share code, notes, and snippets.

@bluepost59
bluepost59 / economy_simulation.py
Last active September 11, 2021 15:57
economy_simulation.py
import os
import time as t
import numpy as np
import matplotlib.pyplot as plt
N_POPULATION = 100
N_INITIAL_BALANCE = 100
MAX_TRADE = 10
N_TICKS = 10000
@bluepost59
bluepost59 / file0.f
Last active December 10, 2018 13:42
fortran+MPIコーディング入門(2) 集団通信 ref: https://qiita.com/Bluepost59/items/f1871b37669b38352a7c
subroutine smp_bcast()
double precision :: xx_bcast = 0d0
integer :: data_num = 1 ! 送信するデータの個数
integer :: origin_rank = 0 ! 送信元プロセスのランク
!ランク0のxx_bcastだけ1d0にする
if(me == 0) then
xx_bcast=1d0
end if
@bluepost59
bluepost59 / file0.txt
Last active December 10, 2018 13:41
fortran+MPIコーディング入門(1) プロセス並列の基本 ref: https://qiita.com/Bluepost59/items/5cce1174ac48367948bc
mpif90 -o smp01 smp01.f90
@bluepost59
bluepost59 / file0.f
Last active October 10, 2018 13:55
続・fortranでもオブジェクト指向したい!「継承と抽象クラス」 ref: https://qiita.com/Bluepost59/items/8d4b7d7713676fe06472
type,extends(parent_class) :: child_class
integer param1
!...
contains
procedure :: method1 => child_method1
!...
end type child_class
@bluepost59
bluepost59 / smp01.cpp
Last active June 24, 2018 13:13
抽象クラスを使うメリット ref: https://qiita.com/Bluepost59/items/eef6f48fdd322b0b9791
#include<iostream>
using std::cout;
using std::endl;
//抽象クラスvehicleの定義
class vehicle{
public:
virtual void start(void)=0;
virtual void stop(void)=0;
};
@bluepost59
bluepost59 / contour.py
Last active October 10, 2018 13:51
資料作りのためのmatplotlib入門(2) 2次元contour図 ref: https://qiita.com/Bluepost59/items/a0869aee34db3f450162
import numpy as np
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
nx = 100
ny = 200
mydata = np.loadtxt('mydata.txt')
xx = np.linspace(0,nx,nx)
@bluepost59
bluepost59 / file0.f
Last active March 11, 2018 09:05
資料作りのためのmatplotlib入門(1) 1次元図 ref: https://qiita.com/Bluepost59/items/f2b0a1a8449440de6a1b
do i=1,Nx
write(UNITNUM,*) i,a(i)
end do
@bluepost59
bluepost59 / sumup.py
Created December 6, 2017 16:00
いろんな方法で累積和を計算して時間を計測する
import time as t
import numpy as np
import sys
smp_num = 10000
mydata = [float(i) for i in range(smp_num)]
res = [0.0 for i in range(smp_num)]
def integ_for():