nvccコンパイル
Macbook Proでcuファイルをコンパイルしようとしたらいろいろ詰まったのでメモ
環境変数
export LIBRARY_PATH="/Developer/GPU Computing/C/common/lib":"/Developer/GPU Computing/C/lib" :/usr/local/lib:$LIBRARY_PATH export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:$DYLD_LIBRARY_PATH export LD_LIBRARY_PATH=/usr/local/cuda/lib:$LD_LIBRARY_PATH export C_INCLUDE_PATH="/Developer/GPU Computing/C/common/inc":/usr/local/cuda/include:$C_INC LUDE_PATH export CPLUS_INCLUDE_PATH="/Developer/GPU Computing/C/common/inc":/usr/local/cuda/include:$C PLUS_INCLUDE_PATH
とりあえず.bashrcに書いておく
cutil.hを使う場合
nvcc main.cu -o main -lcutil_i386
みたいな感じでライブラリを追加。-lcutilじゃダメだった
Heatbugs実行の流れ
かなり適当なメモ
実行の流れはHeatbugModelSwarmのbuildActions内で定義
大事なのは下の2行
[modelActions createActionTo: heat message: M(stepRule)]; actionForEach = [modelActions createActionForEach: heatbugList message: M(step)];
まずHeatSpaceのインターフェースであるDiffuse2dのstepRule関数を実行
この関数で周囲のマスから温度の伝搬を行う
詳細はDiffuse2d.m内の実装を参照
Diffuse2d.mはhttp://pj.freefaculty.org/Swarm/Swarm-src/からダウンロードした
ソースコード内にある
Diffuse2dで出てくるdiscrete2dSiteAtというマクロはDiscrete2d.hに以下のように定義されていて
#define discrete2dSiteAt(l, offsets, x, y) ((l) + (offsets)[(y)] + (x))
座標x, yのポインタを返すマクロになっている
これでx, y上の温度を取得している
次にHeatbugのstep関数を実行
この関数でHeatbugの移動をし,温度を自分がいたマスに残す
詳細はHeatbug.m内の実装を参照
Objective-C Swarmのインストール
Swarm
Swarmについて基本的なことは以下のページに既にまとめられているので
このエントリではObjective-C SwarmをLinuxにインストールする手順を中心に書きます
http://www.unfindable.net/swarm/
インストール先
VirtualBox上のCentOS 5.6 32bitにインストールします。
64bitでも動作はすると思いますが、サンプルのコンパイルがうまくできず断念しました。
インストール
必要なライブラリなどをyumからインストールしたいので
リポジトリを追加します。
EPELリポジトリの追加
# wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm # rpm -ivh epel-release-5-4.noarch.rpm
CentOS Plusの有効化(もしかしたら不要かも)
# vi /etc/yum.repos.d/CentOS-Base.repo ... [centosplus] name=CentOS-$releasever - Plus mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/ gpgcheck=1 enabled=0 ...
のenabled=0をenabled=1にします。
ライブラリのインストール
# yum install -y tcl tcl-devel # yum install -y tk tk-devel # yum install -y blt blt-devel # yum install -y hdf5 hdf5-devel # yum install -y gcc-objc # cd /usr/lib # ln -s libXpm.so.4 libXpm.so
Swarmのインストール
# wget http://pj.freefaculty.org/software/Centos/5/i386/Swarm-nojava/swarm-2.4.1-1nojava.i386.rpm # rpm -ivh swarm-2.4.1-1nojava.i386.rpm
node.jsインストール
Macbook Proにnode.jsをインストールする際のまとめ
git等は既にインストールされていること前提で書いてます。
nvmのインストール
rvm的な物です。バージョンアップ早すぎてソースコードからインストールするのだるいです。
git clone https://github.com/joyent/node.gitとかやると開発バージョン入ったりしてだるいです。
$ git clone git://github.com/creationix/nvm.git ~/.nvm $ . ~/.nvm/nvm.sh
2行目は ~/.bashrcとかに書いておきましょう。
node.js のインストール
$ nvm install v0.4.9 $ nvm use v0.4.9 Now using node v0.4.9 $ node -v v0.4.9
シェルを閉じると設定が消えるようなので~/.bashrcに
nvm use v0.4.9
を追加しておきましょう。
npm のインストール
nvmでnodeをインストールしたときに一緒にインストールしてくれるので不要。
これでnodeを使う環境は出来ました。
パッケージをインストールする際は以下のようにします。
expressのインストール
$ npm install express
or
$ npm install -g express
- g オプションを付けるとパスが通ってどこからでも呼び出せるようになります。
Auto IncrementでないPrimary Key列を作りたい
Railsだとprimary keyの列にはauto incrementがついちゃいますが
auto incrementなしのprimary key列が欲しい時は以下のようにして作れました
http://stackoverflow.com/questions/1585323/how-to-turn-off-auto-increment-in-rails-active-recordより
class CreateUsers < ActiveRecord::Migration def self.up create_table :users, :id=>false do |t| t.column :uid, "int(11) PRIMARY KEY" t.timestamps end end def self.down drop_table :users end end
ただしschema.rbを利用する
rake db:reset
とかしちゃうとauto incrementがついてしまいます
Modelのカラム名でアクセスするとNoMethodError
Modelのカラム名にうっかりclassとか付けちゃうとカラム名でアクセスしたとき例外が出て詰みます
testmodel
class CreateTestmodels < ActiveRecord::Migration def self.up create_table :testmodels do |t| t.string :name t.integer :class t.timestamps end end def self.down drop_table :testmodels end end
実行
$rails c Loading development environment (Rails 3.0.5) ruby-1.9.2-p180 :001 > m = Testmodel.new => #<Testmodel id: nil, name: nil, class: nil, created_at: nil, updated_at: nil> ruby-1.9.2-p180 :002 > m.name = "aaa"
例外
NoMethodError: undefined method `private_method_defined?' for nil:NilClass from /Users/user/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.5/lib/active_support/whiny_nil.rb:48:in `method_missing' from /Users/user/.rvm/gems/ruby-1.9.2-p180/gems/activemodel-3.0.5/lib/active_model/attribute_methods.rb:403:in `guard_private_attribute_method!' from /Users/user/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.5/lib/active_record/attribute_methods.rb:43:in `method_missing'