Skip to content

Instantly share code, notes, and snippets.

@dc1394
dc1394 / mc_xorshift_vec.cpp
Created December 31, 2023 13:25
Twitterのモンテカルロ法のC++版の速度比較コード(Xoshiro256PlusSIMD使用+手動でSIMD (AVX2)ベクトル化)
#include <cstdint> // for std::uint32_t
#include <iomanip> // for std::setprecision
#include <ios> // for std::ios::fixed, std::ios::floatfield
#include <iostream> // for std::cout, std::endl
#define __AVX2_AVAILABLE__
#include "SIMDInstructionSet.h"
#include "Xoshiro256Plus.h"
namespace {
inline double mcpi();
@dc1394
dc1394 / mc_xorshift.cpp
Created December 31, 2023 13:17
Twitterのモンテカルロ法のC++版の速度比較コード(Xoshiro256PlusSIMD使用)
#include <iomanip> // for std::setprecision
#include <ios> // for std::ios::fixed, std::ios::floatfield
#include <iostream> // for std::cout, std::endl
#include <utility> // for std::make_pair, std::pair
#define __AVX2_AVAILABLE__
#include "SIMDInstructionSet.h"
#include "Xoshiro256Plus.h"
namespace {
inline double mcpi();
@dc1394
dc1394 / mc_mt19937.cpp
Created December 31, 2023 13:13
Twitterのモンテカルロ法のC++版の速度比較コード(C++のmt19937)
#include <iomanip> // for std::setprecision
#include <ios> // for std::ios::fixed, std::ios::floatfield
#include <iostream> // for std::cout, std::endl
#include <random> // for std::mt19937, std::uniform_real_distribution
namespace {
inline double mcpi();
}
int main()
@dc1394
dc1394 / mc_crand.cpp
Created December 31, 2023 13:09
Twitterのモンテカルロ法のC++版の速度比較コード(C++に備え付けのrand())
#include <cstdlib> // for std::rand, std::srand
#include <iomanip> // for std::setprecision
#include <ios> // for std::ios::fixed, std::ios::floatfield
#include <iostream> // for std::cout, std::endl
namespace {
inline double mcpi();
}
int main()
@dc1394
dc1394 / mc.cpp
Created December 31, 2023 12:59
Twitterのモンテカルロ法のC++版の速度比較コード(線形合同法自前実装)
#include <cstdint> // for std::int32_t
#include <iomanip> // for std::setprecision
#include <ios> // for std::ios::fixed, std::ios::floatfield
#include <iostream> // for std::cout, std::endl
#include <utility> // for std::make_pair, std::pair
#define USE_MOD 1
namespace {
inline std::pair<std::int32_t, double> LCGs(std::int32_t seed);
@dc1394
dc1394 / mc.cpp
Last active December 29, 2023 07:44
Twitterのモンテカルロ法の速度比較のコード(C++版)
#include <cstdint> // for std::int32_t
#include <iomanip> // for std::setprecision
#include <iostream> // for std::cout, std::endl
#include <ios> // for std::ios::fixed, std::ios::floatfield
#include <utility> // for std::make_pair, std::pair
#define USE_MOD 0
namespace {
std::pair<std::int32_t, double> LCGs(std::int32_t seed);
@dc1394
dc1394 / newton_time.f90
Created December 27, 2023 10:18
Twitterの1D-Newton法の速度比較のコード(Fortran版、時間計測付き)
program main
implicit none
real(8) :: x, v
real(8),allocatable :: xt(:), vt(:)
real(8) :: mass, k, dt
integer :: i, it, nt, clock_rate
integer, dimension(5) :: cp
real(8) :: elapsed_time
mass = 1d0
@dc1394
dc1394 / newton_time.cpp
Created December 27, 2023 10:08
Twitterの1D-Newton法の速度比較のコード(C++版時間計測付き)
#include <chrono> // for std::chrono
#include <fstream> // for std::ofstream
#include <iomanip> // for std::setprecision
#include <ios> // for std::ios::fixed, std::ios::floatfield, std::scientific
#include <iostream> // for std::cout
#include <utility> // for std::make_pair, std::pair
#include <vector> // for std::vector
namespace {
std::pair<double, double> Runge_Kutta_4th(double x, double v, double dt, double mass, double k);
@dc1394
dc1394 / newton_array_time.cpp
Last active December 27, 2023 10:09
Twitterの1D-Newton法の速度比較のコード(C++版、動的配列時間計測付き)
#include <chrono> // for std::chrono
#include <fstream> // for std::ofstream
#include <iomanip> // for std::setprecision
#include <ios> // for std::ios::fixed, std::ios::floatfield, std::scientific
#include <iostream> // for std::cout
#include <utility> // for std::make_pair, std::pair
#include <vector> // for std::vector
namespace {
std::pair<double, double> Runge_Kutta_4th(double x, double v, double dt, double mass, double k);
@dc1394
dc1394 / newton.rs
Created December 26, 2023 12:02
Twitterの1D-Newton法の速度比較のコード(Rust版)
use std::fs::File;
use std::io::Write;
fn main() {
let mass = 1.0;
let k = 1.0;
let dt = 1e-2;
let nt = 100000000;
let mut xt = vec![0.0; nt + 1];