Skip to content

Instantly share code, notes, and snippets.

View masa16's full-sized avatar

Masahiro TANAKA masa16

  • Fujisawa, Japan
View GitHub Profile
@masa16
masa16 / pascal.rb
Created July 22, 2020 08:48
Pascal's triangle
require 'zlib'
def png_chunk(type,data)
[data.bytesize,type,data,Zlib.crc32(type+data)].pack("NA4A*N")
end
def png_save(file,width,height,raw_data)
depth = 8
color_type = 2
File.open(file,'w') do |f|
@masa16
masa16 / gfarm2fs-profile.sh
Last active September 3, 2019 09:29
Script to obtain profiles of current Gfarm mount points
#!/bin/bash
profs="create_time open_time close_time read_time write_time
create_count open_count close_count read_count write_count
read_size write_size"
gfarm_mp=$(awk '/^gfarm2fs .+,user='$USER' / {print $2}' /etc/mtab)
if [ "$gfarm_mp" = "" ]; then
echo "no gfarm mount point" 1>&2
@masa16
masa16 / demo_gfarm_pool.py
Last active June 28, 2018 09:18
Pool のワーカー毎に gfarm2fs でマウントするための関数置き換え
#!/usr/bin/env python
# mpiexec -n <number_of_nodes> /path/to/demo_gfarm_pool.py"
from lsst.daf.persistence import LogicalLocation
from hsc.pipe.base.pool import startPool, Pool, PoolSlave
import gfarm2fs
# invoke gfarm2fs on workers
@masa16
masa16 / gfqsub.md
Last active July 17, 2018 08:43
Gfarm用ジョブキューシステム gfqsub

Gfarm用ジョブキューシステム gfqsub

https://github.com/chokkan/gfqsub

Gfarmファイルシステムに置かれたファイルの局所性を考慮した簡単なジョブキューシステム。岡崎さん作。Pythonで記述。Qiitaの記事で少しだけ触れられている。

使い方

設定ファイル

~/.gfqsub に設定を書く。

@masa16
masa16 / decorator.rb
Last active May 7, 2023 18:50
Decorator for Ruby similar to Python's decorator
module Decorator
@@decorators = []
def decorate(method_name,*args)
@@decorators << [method_name.to_sym,args]
end
def method_added(method_name)
super
return if @@decorators.empty?
decorators = @@decorators.reverse.map{|name,args| [method(name),args]}
@@decorators = []
require_relative 'narray'
def measure(m,s,&b)
t = Time.now
m.times(&b)
printf "%s time=%.3f\n", s, Time.now-t
end
(2..7).each do |x|
n = 10**x
NCORE = ENV['NCORE'].to_i
PARAMS = ENV['PARAMS'].split
SH = ENV['SH']
sync = "sync_begin"
task sync
PARAMS.each do |param|
a = []
NCORE.times.map do |core|
import time
import numpy as np
def measure(label,ary,repeat):
t = time.time()
for j in range(repeat):
ret = 0
for i in range(len(ary)):
ret += ary[i]
print "%16s: %f"%(label,time.time()-t)
code = 'system gets; puts "end"'
host = "tsukuba100"
cmd = "ssh -x -T #{host} \"ruby -e 'eval ARGF.read(#{code.size})'\""
 
r0,w0 = IO.pipe
r1,w1 = IO.pipe
pid = spawn(cmd,:in=>r0,:out=>w1)
 
w0.write(code)
w0.puts("hostname")