HPCメモ

HPC(High Performance Computing)に関連したりしなかったりすることのメモ書き

cmakeでC++ルーチンを呼び出すFortranプログラムをビルドする

自作のライブラリ(C++で作成、C、Fortranのインタフェースあり)をFortranのプログラムから呼び出すサンプルコードを書いてたんですが、CmakeList.txtの作成ではまったので、メモ

cmake fortran c++ mixedlink あたりでぐぐると、

SET_TARGET_PROPERTIESで、LINKER_LANGUAGE をCXXに設定するべし

という解決方法が定番のようです。実際にg++/gfortranの環境であればこれで問題無いんですが、intel コンパイラの場合は、この方法ではリンク時にエラーになります。


Compiling and Linking Intel® Fortran/C Programs

によると、リンク時に"-cxxlib"を渡せと書いてますが、これもうまく動作しなかったので、当面の回避策として、こんな形にしてみました。

project(hoge CXX C Fortran)
.
.
.
add_executable(huga huga.f90)
target_link_libraries(huga my_cxx_lib ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})

要は、CXXコンパイラが暗黙的にリンクするライブラリを強制的にtarget_link_librariesで追加してるだけです。
これでPGIコンパイラとかでも動いてくれたらいいなぁ

chef -zeroでwindows用開発環境を構築(その4)

運用を始めてから気付いたことをバラバラとメモっときます。

gitでエラーになる

gitのレシピを実行すると、こんなエラーが発生する時があります。

FATAL: Errno::EIO: git[C:\WORK\unix_home] (update_home_dir::default line 10) had an error: Errno::EIO: Input/output error - CreateProcessW

ここにissueとして出てますが、gitじゃなくてgit.exeを呼ばないと発生するエラーだそうです。
git resource Errno::EIO on windows · Issue #1622 · chef/chef · GitHub
そのうち解決されると思いますが、とりあえずのワークアラウンドとしてこんな感じに修正しておきました。

if platform_family?('windows')
    git_command="git.exe"
else
    git_command="git"
end

#clone remote repo to $HOME if not exist
if ! ::File.directory?("#{ENV['HOME']}/.git")
    execute "git init" do
        command  "#{git_command} init"
        cwd      "#{ENV['HOME']}"
    end
    execute "git remote add" do
        command  "#{git_command} remote add origin #{node['update_home_directory']['repo']}"
        cwd      "#{ENV['HOME']}"
    end
end

execute "git pull" do
    command  "#{git_command} pull origin master"
    cwd      "#{ENV['HOME']}"
end
execute "git submodule" do
    command  "#{git_command} submodule update --init --recursive"
    cwd      "#{ENV['HOME']}"
end

cloneせずに、わざわざinitしてからpullしてますが、これはこのエラーとは無関係で、gitが実行される前に%HOME%\.chefディレクトリが作られてしまってgit cloneに失敗することへの対策です。

windows_packageの羃等性

githubのページに書かれているように、windows_packageに渡す名前は[コントロールパネル]->[プログラムと機能]のリストに表示されている名前と正確に一致させていないと、インストール済かどうかの判定に失敗します。
opscode-cookbooks/windows · GitHub
でもって、この名前はプログラムによってバージョン名を含むものや含まないものが混在しているので、もしバージョン番号が入っていないソフトだったら、アップデートするのが難しくなるので違う名前にしておきましょう。(うちの環境だとAmazon KindleとかcourvusSKKとかがバージョン番号が無いです)

ログオン時に実行させる

スタートアップに追加するのは、専用のリソースが用意されていて、次のようなコードで登録できます。

windows_auto_run "autohotkey" do
    program node['autohotkey']['program_name']
    not_if  {Registry.value_exists?(AUTO_RUN_KEY, "autohotkey")}
    action  :create
end

ショートカットの追加

ショートカットも専用のリソースがあって、こんな感じで追加できます。

windows_shortcut "#{ENV['USERPROFILE']}\\Desktop\\gvim.lnk" do
    target       exe_path
    description  "gvim"
    action       :create
end

本当はスタートメニューとかタスクバーに登録したいんですが、こっちのやり方は分からず・・・

ファイルの関連付け変更

ファイルの関連付けは、コマンドラインからassocやftypeコマンドを使うのが正しいやり方だと思いますが、面倒なのでレジストリを直接いじります。しかし、ぐぐってみると昔のkeyも有効なようで

"HKEY_CURRENT_USER\\Software\\Classes\\.#{ext}\\shell\\open\\command"

に登録するパターンと

"HKEY_CURRENT_USER\\Software\\Classes\\#{ext}_auto_file\\shell\\open\\command"

に登録するパターンのどちらでも良いようです。(#{ext}は拡張子)

うちの環境でテストした限りでは、

  • 後者の方が優先
  • エクスプローラGUIから設定する画面(ファイルを開くプログラムの選択)には後者の方法で登録しないと表示されない

という問題があるので、後者のkeyを使っています。

具体的にはgvimのレシピの中でこんな感じにしてます。

%w{rb py js txt log c C cpp h f F f90 F90}.each do |ext|
    registry_key "set file type assocication by auto_file #{ext}" do
        key    "HKCU\\Software\\Classes\\#{ext}_auto_file\\shell\\open\\command"
        values [{
            :name => "",
            :type => :string,
            :data => "#{exe_path} %1"
        }]
        recursive true
    end
end

chef-zeroでwindows用開発環境を構築(その3)

再び続けてChef-zero on windowsの話です。

前回までで、まだ足りないソフトがあるものの、windows8.1用のchef-repoを作成してOneDriveに放り込み、chefによる環境設定の運用を開始することができました。
今回は、OndeDrive経由で別のwindowsマシンにも同じ環境を作ってみましょう。

ちなみに、新しいマシンはwindows7 pro(64bit)です。

下準備

msysgitとchef-clientをインストールします。内容は前々回と同じなので、詳細は省略
http://hpcmemo.hatenablog.com/entry/2015/03/19/125319

ノードの作成

chef-repoへ移動して以下のコマンドを実行します。

>chef-client -z
[2015-03-23T12:44:21+09:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 12.0.3
[2015-03-23T12:45:04+09:00] WARN: chef-client doesn't have administrator privileges on node new_pc. This might cause unexpected resource failures. resolving cookbooks for run list: []
Synchronizing Cookbooks:
Compiling Cookbooks...
[2015-03-23T12:45:04+09:00] WARN: Node new_pc has an empty run list.
Converging 0 resources

Running handlers:
Running handlers complete
Chef Client finished, 0/0 resources updated in 43.526 seconds

本当は、新規ノードを作成するには

> knife node create new_pc -z

で良いはずなんですが、何回やっても環境変数EDITORが設定されていないと言われて実行できなかったので・・・

run_listの追加とレシピの適用

1台目のマシンと同じですが、Admin権限をもったコマンドプロンプトで以下のコマンドを実行します。

> knife node  run_list add new_pc firefox windows_initial_settings windows -z
WARNING: No knife configuration file found
new_pc:
  run_list:
    recipe[firefox]
    recipe[windows_initial_settings]
    recipe[windows]
> chef-client -z
[2015-03-25T13:51:33+09:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 12.0.3
resolving cookbooks for run list: ["firefox", "windows_initial_settings", "windows"]
Synchronizing Cookbooks:
  - firefox
  - windows_initial_settings
  - windows
  - chef_handler
Compiling Cookbooks...
Recipe: windows::default
  * chef_gem[win32-api] action install (up to date)
  * chef_gem[win32-service] action install (up to date)
  * chef_gem[windows-api] action install (up to date)
  * chef_gem[windows-pr] action install (up to date)
  * chef_gem[win32-dir] action install (up to date)
  * chef_gem[win32-event] action install (up to date)
  * chef_gem[win32-mutex] action install (up to date)
  Converging 13 resources
Recipe: firefox::default
  * windows_package[Mozilla Firefox 36.0.4 en-US] action install
  Recipe: <Dynamically Defined Resource>
    * remote_file[C:\WORK\unix_home\.chef\local-mode-cache\cache/Firefox Setup 36.0.4.exe] action create
      - update content in file C:\WORK\unix_home\.chef\local-mode-cache\cache/Firefox Setup 36.0.4.exe from e3b0c4 to 15f75d
      (file sizes exceed 10000000 bytes, diff output suppressed)

Recipe: windows_initial_settings::default
  * directory[C:WORK] action create (up to date)
  * git[C:\WORK\unix_home] action syncPassword for 'https://n_so5@bitbucket.org':
 (up to date)
  * env[HOME] action create (up to date)
  * directory[C:\WORK\unix_home\.ssh] action create (up to date)
  * execute[ssh-keygen] action run (skipped due to not_if)
Recipe: windows::default
  * chef_gem[win32-api] action install (up to date)
  * chef_gem[win32-service] action install (up to date)
  * chef_gem[windows-api] action install (up to date)
  * chef_gem[windows-pr] action install (up to date)
  * chef_gem[win32-dir] action install (up to date)
  * chef_gem[win32-event] action install (up to date)
  * chef_gem[win32-mutex] action install (up to date)

Running handlers:
Running handlers complete
Chef Client finished, 2/20 resources updated in 155.402539 seconds

既に環境変数が設定済だったり、鍵が生成済だったりするので、イロイロ飛ばされてますが、あっさりと適用できました。

あとは、インストールする各アプリのレシピを育てていけば、いつでもお手軽に新しいwindowsマシンのセットアップができますね。

chef-zeroでwindows用開発環境を構築(その2)

さて、前回の続きです。

普段、windowsマシンを使う時には、次のような運用方針にしているんですが、このための設定をchefのレシピでなんとかしてみましょう。

  • C:\WORK を作成して、必要なファイル類はそこへ置く
  • bitbucketに置いてあるドットファイルをC:\WORK\unix_homeにcloneしてくる。
  • 環境変数 HOME にC:\WORK\unix_homeを設定
  • sshの鍵を作成

cookbookの作成

まずは、knifeを使って新しいcookbookを作ります。*1

> knife cookbook create windows_initial_settings -z
WARNING: No knife configuration file found
** Creating cookbook windows_initial_settings in C:/Users/n_so5/SkyDrive/chef-repo/cookbooks
** Creating README for cookbook: windows_initial_settings
** Creating CHANGELOG for cookbook: windows_initial_settings
** Creating metadata for cookbook: windows_initial_settings

無事にできたら、次のような感じのディレクトリが生成されているはずです。

>ls -R cookbooks\windows_initial_settings
cookbooks\windows_initial_settings:
CHANGELOG.md  README.md  attributes  definitions  files  libraries  metadata.rb  providers  recipes  resources  templates
cookbooks\windows_initial_settings/attributes:
cookbooks\windows_initial_settings/definitions:
cookbooks\windows_initial_settings/files:
default
cookbooks\windows_initial_settings/files/default:
cookbooks\windows_initial_settings/libraries:
cookbooks\windows_initial_settings/providers:
cookbooks\windows_initial_settings/recipes:
default.rb
cookbooks\windows_initial_settings/resources:
cookbooks\windows_initial_settings/templates:
default
cookbooks\windows_initial_settings/templates/default:

このうちの、recipes/default.rbにつらつらとレシピを書いていきます。

ディレクトリの作成

まず、最初のC:\WORKの作成ですが、これはその名もずばりの"directory"というリソースがあるので、これを使います。
https://docs.chef.io/resource_directory.html

  directory "C:\WORK" do
      action :create
  end

gitでドットファイルを持ってくる

こちらも"git"というリソースがあるので、これを使います。
https://docs.chef.io/resource_git.html

  home_dir="C:\\WORK\\unix_home"
  git "#{home_dir}" do
      repository "https://n_so5@bitbucket.org/XXXX.git"
      enable_submodules true
      action :sync
  end

.vimの下にいくつかsubmoduleとしてvimプラグインリポジトリを入れているので、"enable_submodule true"を指定しています。あと、sshの鍵を未だ登録していない環境からのアクセスを想定しているので、http経由でのアクセスにしています。

環境変数のHOMEを設定

これまた"env"というリソースがあるので、これを使います。
https://docs.chef.io/resource_env.html

  env "HOME" do
      value "#{home_dir}"
      action :create
  end

sshの鍵作成

これまた、chefのリソースでと思いきや、あんまりこういう用途は想定していないのかうまく使えそうな手がありません。とりあえず、executeを使って、ssh-keygenを呼び出すことにします。

  key_filename="C:\WORK\unix_home\.ssh\id_rsa"
  execute "ssh-keygen" do
      command "ssh-keygen -f #{key_filename} -t rsa "
      not_if {::File.exists?(key_filename)}
  end

既に鍵を作成した環境で実行した時に、上書きを避けるため、not_ifで条件を指定しています。

実際に適用してみる

ここまでをまとめてdefault.rbに書いた上で、windows以外の環境では実行されないように

if platform_family?('windows')
...
end

で囲っておきます。

レシピの適用前はこんな状況ですが

> ls C:\WORK
ls: C:\WORK: No such file or directory
> echo %HOME%
C:\Users\n_so5

実際に適用すると

> chef-client -z
[2015-03-19T19:15:33+09:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 12.0.3
resolving cookbooks for run list: ["firefox", "windows", "windows_initial_settings"]
Synchronizing Cookbooks:
  - firefox
  - windows
  - windows_initial_settings
  - chef_handler
Compiling Cookbooks...
Recipe: windows::default
  * chef_gem[win32-api] action install (up to date)
  * chef_gem[win32-service] action install (up to date)
  * chef_gem[windows-api] action install (up to date)
  * chef_gem[windows-pr] action install (up to date)
  * chef_gem[win32-dir] action install (up to date)
  * chef_gem[win32-event] action install (up to date)
  * chef_gem[win32-mutex] action install (up to date)
  Converging 13 resources
Recipe: firefox::default
  * windows_package[Mozilla Firefox 36.0.1 en-US] action install
  Recipe: <Dynamically Defined Resource>
    * remote_file[C:\Users\n_so5\.chef\local-mode-cache\cache/Firefox Setup 36.0.1.exe] action create (up to date)

Recipe: windows::default
  * chef_gem[win32-api] action install (up to date)
  * chef_gem[win32-service] action install (up to date)
  * chef_gem[windows-api] action install (up to date)
  * chef_gem[windows-pr] action install (up to date)
  * chef_gem[win32-dir] action install (up to date)
  * chef_gem[win32-event] action install (up to date)
  * chef_gem[win32-mutex] action install (up to date)
Recipe: windows_initial_settings::default
  * directory[C:WORK] action create
    - create new directory C:WORK
  * git[C:\WORK\unix_home] action syncPassword for 'https://n_so5@bitbucket.org':
Password for 'https://n_so5@bitbucket.org':

    - clone from https://n_so5@bitbucket.org/XXXXX into C:\WORK\unix_home
    - checkout ref 26ea7cf8d79fb68b4273bc133c6165c636248b08 branch HEAD
  * directory[C:\WORK\unix_home\.ssh] action create
    - create new directory
  * execute[ssh-keygen] action runEnter passphrase (empty for no passphrase):
Enter same passphrase again:

    - execute ssh-keygen -f C:\WORK\unix_home\.ssh\id_rsa -t rsa

Running handlers:
Running handlers complete

といった具合に適用されます。gitでアクセスしている時にはbitbucketのパスワードを聞かれるので、入力してください。あと、ssh-keygenのレシピを適用している時も普通にssh-keygenした時と同じようにパスフレーズの入力を求められます。

でもって、どういう状態になったかと言うと

>ls C:\WORK
unix_home
> ls C:\WORK\unix_home\.ssh\
id_rsa  id_rsa.pub

> echo %HOME%
C:\Users\n_so5

あら?環境変数の変更が反映されていない・・・と思ったけどこれは単にコマンドプロンプトを再起動すれば反映されます。コマンドプロンプトを立ち上げ直すと、無事に反映されています。あと、.vim/bundleの下に色々と入っているのも確認。

> echo %HOME%
C:\WORK\unix_home
>ls %HOME%/.vim/bundle/*
C:\WORK\unix_home/.vim\bundle/indentLine:
README.md  after  doc

C:\WORK\unix_home/.vim\bundle/pydiction:
README  README.md  after  complete-dict  pydiction.py

C:\WORK\unix_home/.vim\bundle/syntastic:
CONTRIBUTING.md  LICENCE  README.markdown  _assets  autoload  doc  plugin  syntax_checkers

ついでに、この状態から再実行するとどうなるか試してみました。

> cdhef-client -z
[2015-03-19T19:29:26+09:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 12.0.3
resolving cookbooks for run list: ["firefox", "windows", "windows_initial_settings"]
Synchronizing Cookbooks:
  - firefox
  - windows
  - windows_initial_settings
  - chef_handler
Compiling Cookbooks...
Recipe: windows::default
  * chef_gem[win32-api] action install (up to date)
  * chef_gem[win32-service] action install (up to date)
  * chef_gem[windows-api] action install (up to date)
  * chef_gem[windows-pr] action install (up to date)
  * chef_gem[win32-dir] action install (up to date)
  * chef_gem[win32-event] action install (up to date)
  * chef_gem[win32-mutex] action install (up to date)
  Converging 13 resources
Recipe: firefox::default
  * windows_package[Mozilla Firefox 36.0.1 en-US] action install
  Recipe: <Dynamically Defined Resource>
    * remote_file[C:\WORK\unix_home\.chef\local-mode-cache\cache/Firefox Setup 36.0.1.exe] action create
      - create new file C:\WORK\unix_home\.chef\local-mode-cache\cache/Firefox Setup 36.0.1.exe
      - update content in file C:\WORK\unix_home\.chef\local-mode-cache\cache/Firefox Setup 36.0.1.exe from none to ad32ad
      (file sizes exceed 10000000 bytes, diff output suppressed)

Recipe: windows::default
  * chef_gem[win32-api] action install (up to date)
  * chef_gem[win32-service] action install (up to date)
  * chef_gem[windows-api] action install (up to date)
  * chef_gem[windows-pr] action install (up to date)
  * chef_gem[win32-dir] action install (up to date)
  * chef_gem[win32-event] action install (up to date)
  * chef_gem[win32-mutex] action install (up to date)
Recipe: windows_initial_settings::default
  * directory[C:WORK] action create (up to date)
  * git[C:\WORK\unix_home] action syncPassword for 'https://n_so5@bitbucket.org':
 (up to date)
  * env[HOME] action create (up to date)
  * directory[C:\WORK\unix_home\.ssh] action create (up to date)
  * execute[ssh-keygen] action run (skipped due to not_if)

Running handlers:
Running handlers complete
Chef Client finished, 2/20 resources updated in 417.811231 seconds

%HOME%を設定した影響で、firefoxのアーカイブをキャッシュしてる場所が変わるので、アーカイブを再ダウンロードしていますが、他は(up to date)と表示されて、するすると終わっていきます。

とりあえず今日のとこはこれで終わり。

*1:このメタファー破綻してないか・・・?

chef-zeroでwindows用開発環境を構築

最近、遅ればせながら

入門Chef Solo - Infrastructure as Code

入門Chef Solo - Infrastructure as Code

を読んだので、chefで遊んでいます。

普段利用する開発環境の構築なんかに使うぶんにはお手軽にできそうなんですがwindowsにインストールしてwindows環境の構築に使ってるって情報があんまり多くないみたいなので、ざっくりとまとめてみました。

インストール先の環境

マシンはDell Venue8 pro、ソフト環境はこんな感じです。

  • windows8.1 update (32bit版)
  • chef client v12.0.3-1

運用方法

chefを使ったシステムの構成は、ここの絵みたいに設定ファイルなどをまとめたchef-repoというレポジトリをworkstationと呼ばれるマシンに用意して、これをリモートにあるchef-server経由で管理対象マシン(node)に適用する。ということになっています。

An Overview of Chef — Chef Docs

今回は、nodeは全部windows(でOneDriveがインストール済)なのと、自分のマシンにしか適用しないので、次のような方針を採用しました。

  • chef-repoはOneDrive上に構築
  • レシピの適用はローカルマシン上でchef-clientのローカルモードを使って行う

下準備

msysgitのインストール

Git for Windows
のページへ行ってパッケージをダウンロード/インストールします。

chef-clientのインストール

まずはダウンロードページへ行きます。
Chef Client | Chef Downloads | Chef
左にあるプルダウンメニューから"windows" "8" "x86_64"を選びます。
今回のインストール先は32bit環境ですが、x86_64を選んでください。*1
msiファイルへのリンクが表示されるので、ダウンロードしてインストールしてください。途中で聞かれるものは全てデフォルトで大丈夫です。

インストールが完了すると

C:\opscode\chef\bin

にイロイロと入ってます。

chef-repoの作成

githubで公開されている、オフィシャルなchef-repoをcloneしてきます。そのあと、元のoriginをupstreamに変えた上で、適当なリポジトリ(私はbitbucketを使ってますが)をoriginに設定します。

> git clone git://github.com/chef/chef-repo.git
> cd chef-repo
> git remote rename origin upstream
> git remote add origin http://bitbucket.org/XXXXXX
> git checkout -b windows
> git push origin windows

公開されているcookbookをインポート

入れたいものはイロイロとあるんですが、とりあえずテストのためにsupermarketにあるfirefoxのcookbookをインポートしてインストールしてみます。

firefox Cookbook - Chef Supermarket

コマンドプロンプトから、さっき作ったchef-repoディレクトリで以下のコマンドを実行します。
warningが出てますがlocalmode(-z)の時には不要な設定ファイルが無いって話なので問題ないです。

>knife cookbook site install firefox -z
WARNING: No knife configuration file found
Installing firefox to C:/Users/n_so5/SkyDrive/chef-repo/cookbooks
Checking out the master branch.
Creating pristine copy branch chef-vendor-firefox
Downloading firefox from the cookbooks site at version 2.0.0 to C:/Users/n_so5/SkyDrive/chef-repo/cookbooks/firefox.tar.gz
Cookbook saved: C:/Users/n_so5/SkyDrive/chef-repo/cookbooks/firefox.tar.gz
Removing pre-existing version.
Uncompressing firefox version 2.0.0.
removing downloaded tarball
1 files updated, committing changes
Creating tag cookbook-site-imported-firefox-2.0.0
Checking out the master branch.
Updating e3efb8c..72fcfc0
Fast-forward
 cookbooks/firefox/.gitignore            |  6 +++
 cookbooks/firefox/.kitchen.yml          | 20 +++++++
 cookbooks/firefox/.rubocop.yml          | 20 +++++++
 cookbooks/firefox/.travis.yml           | 10 ++++
 cookbooks/firefox/Berksfile             |  5 ++
 cookbooks/firefox/CHANGELOG.md          | 39 ++++++++++++++
 cookbooks/firefox/Gemfile               |  7 +++
 cookbooks/firefox/README.md             | 46 +++++++++++++++++
 cookbooks/firefox/attributes/default.rb | 24 +++++++++
 cookbooks/firefox/chefignore            | 92 +++++++++++++++++++++++++++++++++
 cookbooks/firefox/libraries/default.rb  | 47 +++++++++++++++++
 cookbooks/firefox/metadata.json         | 43 +++++++++++++++
 cookbooks/firefox/metadata.rb           | 15 ++++++
 cookbooks/firefox/recipes/default.rb    | 42 +++++++++++++++
 14 files changed, 416 insertions(+)
 create mode 100644 cookbooks/firefox/.gitignore
 create mode 100644 cookbooks/firefox/.kitchen.yml
 create mode 100644 cookbooks/firefox/.rubocop.yml
 create mode 100644 cookbooks/firefox/.travis.yml
 create mode 100644 cookbooks/firefox/Berksfile
 create mode 100644 cookbooks/firefox/CHANGELOG.md
 create mode 100644 cookbooks/firefox/Gemfile
 create mode 100644 cookbooks/firefox/README.md
 create mode 100644 cookbooks/firefox/attributes/default.rb
 create mode 100644 cookbooks/firefox/chefignore
 create mode 100644 cookbooks/firefox/libraries/default.rb
 create mode 100644 cookbooks/firefox/metadata.json
 create mode 100644 cookbooks/firefox/metadata.rb
 create mode 100644 cookbooks/firefox/recipes/default.rb
Cookbook firefox version 2.0.0 successfully installed

しれっとgitにコミットまでしてくれてますね。これはありがたい。

ローカルマシンへ適用

ダウンロードしてきたレシピを適用するには、ノードオブジェクトを作成して、レシピを適用対象にして、最後にcookという流れなんですが、ノードオブジェクトはchef-client -zを実行すれば、作ってくれるようなので、まず一回実行します。

> chef-client -z 
[2015-03-18T09:07:21+09:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 12.0.3
[2015-03-18T09:08:18+09:00] WARN: chef-client doesn't have administrator privileges on node venue8. This might cause unexpected resource failures.
resolving cookbooks for run list: []
Synchronizing Cookbooks:
Compiling Cookbooks...
[2015-03-18T09:08:18+09:00] WARN: Node venue8 has an empty run list.
Converging 0 resources

Running handlers:
Running handlers complete
Chef Client finished, 0/0 resources updated in 56.203554 seconds

無事にvenue8*2のノードが作成されて、「run listが空っぽだから0個convergeしました。」と表示されたら終了です。

では、さっきインストールしたfirefoxのレシピを適用対象にします。

> knife node run_list add venue8 firefox -z
WARNING: No knife configuration file found
venue8:
  run_list: recipe[firefox]

最後にこのレシピを適用します。
今回は管理者権限が必要になるので、コマンドプロンプトを「管理者権限で実行」で立ち上げなおしてください。でもって、chef-clientをポチっとなすると

> chef-client -z
[2015-03-18T19:37:50+09:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 12.0.3
resolving cookbooks for run list: ["firefox"]
Synchronizing Cookbooks:
  - firefox
Compiling Cookbooks...
Converging 1 resources
Recipe: firefox::default
  * windows_package[Mozilla Firefox 36.0.1 en-US] action install

    ================================================================================
    Error executing action `install` on resource 'windows_package[Mozilla Firefox 36.0.1 en-US]'
    ================================================================================

    RuntimeError
    ------------
    Unable to find a Chef::Provider::Package::Windows provider for installer_type 'custom'

    Resource Declaration:
    ---------------------
    # In C:/WORK/unix_home/.chef/local-mode-cache/cache/cookbooks/firefox/recipes/default.rb

     25:   windows_package "Mozilla Firefox #{version} #{node['firefox']['lang']}" do
     26:     source url
     27:     installer_type :custom
     28:     options '-ms'
     29:     action :install
     30:   end
     31: elsif platform_family?('mac_os_x')

    Compiled Resource:
    ------------------
    # Declared in C:/WORK/unix_home/.chef/local-mode-cache/cache/cookbooks/firefox/recipes/default.rb:25:in `from_file'

    windows_package("Mozilla Firefox 36.0.1 en-US") do
      action [:install]
      retries 0
      retry_delay 2
      default_guard_interpreter :default
      options "-ms"
      package_name "Mozilla Firefox 36.0.1 en-US"
      source "C:\\https:\\download-installer.cdn.mozilla.net\\pub\\firefox\\releases\\latest\\win32\\en-US\\Firefox%20Setup%2036.0.1.exe"
      timeout 600
      installer_type :custom
      returns [0]
      declared_type :windows_package
      cookbook_name "firefox"
      recipe_name "default"
    end


Running handlers:
[2015-03-18T19:38:39+09:00] ERROR: Running exception handlers
Running handlers complete
[2015-03-18T19:38:39+09:00] ERROR: Exception handlers complete
[2015-03-18T19:38:39+09:00] FATAL: Stacktrace dumped to C:/WORK/unix_home/.chef/local-mode-cache/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated in 47.820474 seconds
[2015-03-18T19:38:39+09:00] FATAL: RuntimeError: windows_package[Mozilla Firefox 36.0.1 en-US] (firefox::default line 25) had an error: RuntimeError: Unable to find a Chef::Provider::Package::Windows provider for installer_type 'custom'

あら?
なんか、手順が抜けてるのかと思ってエラーメッセージでぐぐってみたところ、windows用の便利コマンド群をいれる必要があったらしいので、ダウンロードしてきて、run_listに追加します。

> knife cookbook site install windows -z
WARNING: No knife configuration file found
Installing windows to C:/Users/n_so5/SkyDrive/chef-repo/cookbooks
Checking out the master branch.
Creating pristine copy branch chef-vendor-windows
Downloading windows from the cookbooks site at version 1.36.6 to C:/Users/n_so5/SkyDrive/chef-repo/cookbooks/windows.tar.gz
Cookbook saved: C:/Users/n_so5/SkyDrive/chef-repo/cookbooks/windows.tar.gz
Removing pre-existing version.
Uncompressing windows version 1.36.6.
removing downloaded tarball
1 files updated, committing changes
Creating tag cookbook-site-imported-windows-1.36.6
Checking out the master branch.
Updating 22cf2eb..a01a793
Fast-forward
 cookbooks/windows/CHANGELOG.md                     | 320 +++++++++
 cookbooks/windows/README.md                        | 749 +++++++++++++++++++++
 cookbooks/windows/attributes/default.rb            |  24 +
 .../default/handlers/windows_reboot_handler.rb     |  76 +++
 cookbooks/windows/libraries/feature_base.rb        |  59 ++
 cookbooks/windows/libraries/matchers.rb            | 465 +++++++++++++
 cookbooks/windows/libraries/powershell_helper.rb   |  59 ++
 cookbooks/windows/libraries/powershell_out.rb      |  79 +++
 cookbooks/windows/libraries/registry_helper.rb     | 364 ++++++++++
 cookbooks/windows/libraries/version.rb             | 207 ++++++
 .../libraries/windows_architecture_helper.rb       |  87 +++
 cookbooks/windows/libraries/windows_helper.rb      | 148 ++++
 cookbooks/windows/libraries/windows_package.rb     | 224 ++++++
 cookbooks/windows/libraries/windows_privileged.rb  |  94 +++
 cookbooks/windows/libraries/wmi_helper.rb          |  32 +
 cookbooks/windows/metadata.json                    |  31 +
 cookbooks/windows/providers/auto_run.rb            |  33 +
 cookbooks/windows/providers/batch.rb               |  63 ++
 cookbooks/windows/providers/feature_dism.rb        |  64 ++
 cookbooks/windows/providers/feature_powershell.rb  |  38 ++
 .../windows/providers/feature_servermanagercmd.rb  |  61 ++
 cookbooks/windows/providers/font.rb                |  69 ++
 cookbooks/windows/providers/pagefile.rb            | 153 +++++
 cookbooks/windows/providers/path.rb                |  52 ++
 cookbooks/windows/providers/printer.rb             | 101 +++
 cookbooks/windows/providers/printer_port.rb        | 103 +++
 cookbooks/windows/providers/reboot.rb              |  33 +
 cookbooks/windows/providers/registry.rb            |  75 +++
 cookbooks/windows/providers/shortcut.rb            |  56 ++
 cookbooks/windows/providers/task.rb                | 167 +++++
 cookbooks/windows/providers/zipfile.rb             |  93 +++
 cookbooks/windows/recipes/default.rb               |  34 +
 cookbooks/windows/recipes/reboot_handler.rb        |  32 +
 cookbooks/windows/resources/auto_run.rb            |  30 +
 cookbooks/windows/resources/batch.rb               |  36 +
 cookbooks/windows/resources/feature.rb             |  44 ++
 cookbooks/windows/resources/font.rb                |  25 +
 cookbooks/windows/resources/pagefile.rb            |  29 +
 cookbooks/windows/resources/path.rb                |  28 +
 cookbooks/windows/resources/printer.rb             |  41 ++
 cookbooks/windows/resources/printer_port.rb        |  40 ++
 cookbooks/windows/resources/reboot.rb              |  29 +
 cookbooks/windows/resources/registry.rb            |  34 +
 cookbooks/windows/resources/shortcut.rb            |  35 +
 cookbooks/windows/resources/task.rb                |  50 ++
 cookbooks/windows/resources/zipfile.rb             |  33 +
 46 files changed, 4699 insertions(+)
 create mode 100644 cookbooks/windows/CHANGELOG.md
 create mode 100644 cookbooks/windows/README.md
 create mode 100644 cookbooks/windows/attributes/default.rb
 create mode 100644 cookbooks/windows/files/default/handlers/windows_reboot_handler.rb
 create mode 100644 cookbooks/windows/libraries/feature_base.rb
 create mode 100644 cookbooks/windows/libraries/matchers.rb
 create mode 100644 cookbooks/windows/libraries/powershell_helper.rb
 create mode 100644 cookbooks/windows/libraries/powershell_out.rb
 create mode 100644 cookbooks/windows/libraries/registry_helper.rb
 create mode 100644 cookbooks/windows/libraries/version.rb
 create mode 100644 cookbooks/windows/libraries/windows_architecture_helper.rb
 create mode 100644 cookbooks/windows/libraries/windows_helper.rb
 create mode 100644 cookbooks/windows/libraries/windows_package.rb
 create mode 100644 cookbooks/windows/libraries/windows_privileged.rb
 create mode 100644 cookbooks/windows/libraries/wmi_helper.rb
 create mode 100644 cookbooks/windows/metadata.json
 create mode 100644 cookbooks/windows/providers/auto_run.rb
 create mode 100644 cookbooks/windows/providers/batch.rb
 create mode 100644 cookbooks/windows/providers/feature_dism.rb
 create mode 100644 cookbooks/windows/providers/feature_powershell.rb
 create mode 100644 cookbooks/windows/providers/feature_servermanagercmd.rb
 create mode 100644 cookbooks/windows/providers/font.rb
 create mode 100644 cookbooks/windows/providers/pagefile.rb
 create mode 100644 cookbooks/windows/providers/path.rb
 create mode 100644 cookbooks/windows/providers/printer.rb
 create mode 100644 cookbooks/windows/providers/printer_port.rb
 create mode 100644 cookbooks/windows/providers/reboot.rb
 create mode 100644 cookbooks/windows/providers/registry.rb
 create mode 100644 cookbooks/windows/providers/shortcut.rb
 create mode 100644 cookbooks/windows/providers/task.rb
 create mode 100644 cookbooks/windows/providers/zipfile.rb
 create mode 100644 cookbooks/windows/recipes/default.rb
 create mode 100644 cookbooks/windows/recipes/reboot_handler.rb
 create mode 100644 cookbooks/windows/resources/auto_run.rb
 create mode 100644 cookbooks/windows/resources/batch.rb
 create mode 100644 cookbooks/windows/resources/feature.rb
 create mode 100644 cookbooks/windows/resources/font.rb
 create mode 100644 cookbooks/windows/resources/pagefile.rb
 create mode 100644 cookbooks/windows/resources/path.rb
 create mode 100644 cookbooks/windows/resources/printer.rb
 create mode 100644 cookbooks/windows/resources/printer_port.rb
 create mode 100644 cookbooks/windows/resources/reboot.rb
 create mode 100644 cookbooks/windows/resources/registry.rb
 create mode 100644 cookbooks/windows/resources/shortcut.rb
 create mode 100644 cookbooks/windows/resources/task.rb
 create mode 100644 cookbooks/windows/resources/zipfile.rb
Cookbook windows version 1.36.6 successfully installed
Installing chef_handler to C:/Users/n_so5/SkyDrive/chef-repo/cookbooks
Checking out the master branch.
Creating pristine copy branch chef-vendor-chef_handler
Downloading chef_handler from the cookbooks site at version 1.1.6 to C:/Users/n_so5/SkyDrive/chef-repo/cookbooks/chef_handler.tar.gz
Cookbook saved: C:/Users/n_so5/SkyDrive/chef-repo/cookbooks/chef_handler.tar.gz
Removing pre-existing version.
Uncompressing chef_handler version 1.1.6.
removing downloaded tarball
1 files updated, committing changes
Creating tag cookbook-site-imported-chef_handler-1.1.6
Checking out the master branch.
Updating a01a793..26b9666
Fast-forward
 cookbooks/chef_handler/CHANGELOG.md                |  44 +++++++++
 cookbooks/chef_handler/README.md                   | 103 +++++++++++++++++++++
 cookbooks/chef_handler/attributes/default.rb       |  30 ++++++
 .../chef_handler/files/default/handlers/README     |   1 +
 cookbooks/chef_handler/libraries/matchers.rb       |  29 ++++++
 cookbooks/chef_handler/metadata.json               |  29 ++++++
 cookbooks/chef_handler/metadata.rb                 |   7 ++
 cookbooks/chef_handler/providers/default.rb        |  97 +++++++++++++++++++
 cookbooks/chef_handler/recipes/default.rb          |  33 +++++++
 cookbooks/chef_handler/recipes/json_file.rb        |  28 ++++++
 cookbooks/chef_handler/resources/default.rb        |  34 +++++++
 11 files changed, 435 insertions(+)
 create mode 100644 cookbooks/chef_handler/CHANGELOG.md
 create mode 100644 cookbooks/chef_handler/README.md
 create mode 100644 cookbooks/chef_handler/attributes/default.rb
 create mode 100644 cookbooks/chef_handler/files/default/handlers/README
 create mode 100644 cookbooks/chef_handler/libraries/matchers.rb
 create mode 100644 cookbooks/chef_handler/metadata.json
 create mode 100644 cookbooks/chef_handler/metadata.rb
 create mode 100644 cookbooks/chef_handler/providers/default.rb
 create mode 100644 cookbooks/chef_handler/recipes/default.rb
 create mode 100644 cookbooks/chef_handler/recipes/json_file.rb
 create mode 100644 cookbooks/chef_handler/resources/default.rb
Cookbook chef_handler version 1.1.6 successfully installed

>knife node run_list add venue8 windows -z
WARNING: No knife configuration file found
venue8:
  run_list:
    recipe[firefox]
    recipe[windows]

あらためて、 ポチっとなっと

> chef-client -z
[2015-03-19T08:48:04+09:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 12.0.3
resolving cookbooks for run list: ["firefox", "windows"]
Synchronizing Cookbooks:
  - firefox
  - windows
  - chef_handler
Compiling Cookbooks...
Recipe: windows::default
  * chef_gem[win32-api] action install (up to date)
  * chef_gem[win32-service] action install (up to date)
  * chef_gem[windows-api] action install (up to date)
  * chef_gem[windows-pr] action install (up to date)
  * chef_gem[win32-dir] action install (up to date)
  * chef_gem[win32-event] action install (up to date)
  * chef_gem[win32-mutex] action install (up to date)
  Converging 8 resources
Recipe: firefox::default
  * windows_package[Mozilla Firefox 36.0.1 en-US] action install
  Recipe: <Dynamically Defined Resource>
    * remote_file[C:\WORK\unix_home\.chef\local-mode-cache\cache/Firefox Setup 36.0.1.exe] action create
      - create new file C:\WORK\unix_home\.chef\local-mode-cache\cache/Firefox Setup 36.0.1.exe
      - update content in file C:\WORK\unix_home\.chef\local-mode-cache\cache/Firefox Setup 36.0.1.exe from none to ad32ad
      (file sizes exceed 10000000 bytes, diff output suppressed)

Recipe: windows::default
  * chef_gem[win32-api] action install (up to date)
  * chef_gem[win32-service] action install (up to date)
  * chef_gem[windows-api] action install (up to date)
  * chef_gem[windows-pr] action install (up to date)
  * chef_gem[win32-dir] action install (up to date)
  * chef_gem[win32-event] action install (up to date)
  * chef_gem[win32-mutex] action install (up to date)

Running handlers:
Running handlers complete
Chef Client finished, 2/16 resources updated in 182.121495 seconds

今度は無事にインストールできました。
先にwindowsのレシピを適用してから、firefoxを入れないといけないはずですが、その辺は自動的に解決してくれるようですね。*3


次回は、ソフトのインストール以外の設定をしてみます。

*1:そもそもwindows8だとx86_64しか選択肢はありませんが・・・

*2:本当は8proですが・・・

*3:依存性の情報もってるんだったら、最初にwindows rerepiを適用する前にfirefoxを入れようとした時にもっと分かりやすいメッセージ出してくれりゃいいのに・・・

CPU affinityの制御

OpenMPを使ったスレッド並列プログラム実行時のaffinity制御方法を、以前blogに書いたような気がするんだけど、検索しても出てこなかったので、改めてメモしておきます。

CPU bindの方法

CPU coreに対してスレッドをバインドする(=マイグレーションさせない)ためには、
実行時にそれぞれ以下の環境変数を設定します。

Intelコンパイラ

無し(のはず)
後述のKMP_AFFINITYを設定すれば、自動的にバインドされるんですが、特定のcoreの中だけで自由にマイグレーションしても良いなんていう設定はありません。*1

PGIコンパイラ

MP_BIND=yes

GCC

OMP_PROC_BIND=TRUE

どのコアを使うか明示的に指定する方法

こちらも同じく実行時の環境変数で設定します。

Intelコンパイラ

KMP_AFFINITY={compact|scatter|explicit}
compactを設定すると、なるべく使用するコアが密集するように選ばれ、scatterを設定すると分散するように選ばれる。
explicitの場合は、後述のPGIコンパイラGCCのように明示的に指定されたcore idのみが使われます。

PGIコンパイラ

MP_BLIST={0, 2, 4}
リストにあるcore idのコアのみを使って実行

GCC

GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"
リストにあるcore id(0, 3, 1, 2, 4, 6, 8, 10, 12, 14)のコアのみを使う
生成したスレッド数に対して、リストにあるcoreが足りなければ、先頭に戻ってさらに順次割り当てられます。


参考資料:
Intel
Thread Affinity Interface (Linux* and Windows*)

GCC
OMP_PROC_BIND - GNU libgomp
GOMP_CPU_AFFINITY - GNU libgomp

*1:必要だったらnumctlでやってくれってことでしょうかね

zlib関連のメモ

zlib関連のlink集です。

配布元
zlib Home Site

ファイルフォーマットやアルゴリズムの解説など
RFC 1950 - ZLIB Compressed Data Format Specification version 3.3
RFC 1951 - DEFLATE Compressed Data Format Specification version 1.3
RFC 1952 - GZIP file format specification version 4.3

Deflate


使い方の解説
zlib Usage Example
zlib の使い方
zlib 入門


今のところ使い方の解説に上げた3サイトを見比べつつ、zlib.hを見るのが一番分かり易いです。