nfsマウント
ネットワークを通じてクライアントホストにサーバの特定のディレクトリをマウントすることができるnfsマウント。bvmeにrikkyo_vineの/home/gauge以下をマントしたいので、とりあえずやってみた。
NFS のサーバー側(ファイルを提供する側)は portmap(もしくは rpc.portmap), rpc.mountd(もしくは mountd), rpc.nfsd(もしくは nfsd)という3つのプログラムを使ってファイルの提供をおこなう。上記全てが正しく動作していることが必要。
そして、それらのプログラムが参照する設定ファイルの記述で、どのディレクトリを公開するかを決め、また、ディレクトリにアクセスできるサーバーを決定する。
まずサーバ側。今でいうと提供する側なのでrikkyo_vineになる。
設定するファイルは以2つ。
・/etc/exports
・/etc/hosts.allow
IPの方が信頼できるので、/etc/hostsはいじりませんでした。
■■サーバ側
■/etc/exports
クライアントに export するファイルシステムを指定する。XXはクライアントのIPアドレス。
今は/home/gaugeをマウントさせてあげたいわけだから
/home/gauge 172.27.224.XX(rw,no_root_squash)
(rwは読み書きおk、no_root_squashはオプションで、クライアントの root が NFS サーバにアクセス要求したときに匿名を表す nobody に置き換えるかどうかを設定する)
を書き加える。
■/etc/hosts.allow
/etc/hosts.allow の設定
NFS は portmap を使うから、/etc/hosts.allow で クライアントがサーバの portmap を使ってもいいように設定する。
portmap : 172.27.224.XX : allow
変更を加えたら、
# /etc/rc.d/init.d/nfs stop
# /etc/rc.d/init.d/nfs start
または、
# /etc/rc.d/init.d/portmap restart
# /etc/rc.d/init.d/inet restart
# /usr/sbin/rpc.mountd
# /usr/sbin/rpc.nfsd
# /usr/sbin/exportfs -a
で変更を反映出来る。また、既にportmapを起動しているときは、
# exportfs -ra
で、/etc/exportsの変更を反映出来る。
NFSで起動しているソフト、デーモンは以下
プログラム バージョン プロトコル ポート
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100024 1 udp 55685 status
100024 1 tcp 48852 status
100011 1 udp 875 rquotad
100011 2 udp 875 rquotad
100011 1 tcp 875 rquotad
100011 2 tcp 875 rquotad
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100021 1 udp 33017 nlockmgr
100021 3 udp 33017 nlockmgr
100021 4 udp 33017 nlockmgr
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100021 1 tcp 55161 nlockmgr
100021 3 tcp 55161 nlockmgr
100021 4 tcp 55161 nlockmgr
100005 1 udp 46327 mountd
100005 1 tcp 58391 mountd
100005 2 udp 46327 mountd
100005 2 tcp 58391 mountd
100005 3 udp 46327 mountd
100005 3 tcp 58391 mountd
■■クライアント側
# less /proc/filesystems | grep nfs
で、nfsが出てこなかったら、
#modprobe nfs
を実行、他のプログラムと関連性があるので、insmodよりもmodproveで行う。
とりあえず、マウント出来るかためしてみる。YYはサーバのIPアドレス。
# showmount -a 172.27.224.YY mount clntudp_create: RPC: Port mapper failure - RPC: Unable to receive # mount -t nfs -o rsize=1024,wsize=1024 172.27.224.YY:/home/gauge /mnt/gauge mount: RPC: Remote system error - No route to host
うーむ。
出来ない。
クライアントのポートマッパも起動してるんだけどなー。
とりあえずクライアント側もnfsを起動させてみる。
[root@bvme /]# /etc/rc.d/init.d/portmap stop Stopping portmapper: [ OK ] [root@bvme /]# /etc/rc.d/init.d/portmap start Starting portmapper: [ OK ] [root@bvme /]# /etc/rc.d/init.d/nfs start Starting NFS services: [ OK ] Starting NFS quotas: [ OK ] Starting NFS daemon: [ OK ] Starting NFS mountd: [ OK ] [root@bvme /]# mount -t nfs -o rsize=1024,wsize=1024 172.27.224.YY:/home/gauge /mnt/gauge mount: RPC: Remote system error - No route to host
変わらない!
# 5/7 追記
/etc/rc.d/init.d/iptable stop
で、一時的にファイアウォールの設定をなくすことで出来た。
Ntupleを使ってみた。
インタプリタモードで条件に合わせてグラフをプロット出来るクラス。Ntupleを使ってみた。参考は前回と一緒。
ソースは以下
1 #include "TApplication.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <math.h>
5 #include <TROOT.h>
6 #include <TStyle.h>
7 #include <TNtuple.h> /* header file for Ntuple */
8 #include <TFile.h>
9
10 int main(int argc, char **argv){
11 //TApplication theApp("App", &argc, argv);
12
13 gROOT->SetStyle("Plain");
14 gStyle->SetOptStat("neiuoMR");
15 gStyle->SetPalette(1);
16 //
17 double N; /* factor */
18 double mu; /* mean */
19 double sigma; /* standard deviation */
20 //
21 double x1;
22 double x1_max, x1_min;
23 double x2;
24 double x2_max, x2_min;
25 double x3;
26 double x3_max, x3_min;
27
28 double y1_ref; /* reference value */
29 double y1_try; /* trial value */
30 double y3_ref; /* reference value */
31 double y3_try; /* trial value */
32
33 mu= 1.0;
34 sigma= 0.5;
35 N= 1./ sqrt(2.*M_PI) / sigma;
36 //
37 x1_max=+3.0;
38 x1_min=-1.0;
39 x2_max=+20.;
40 x2_min=-15.;
41 x3_max=+3.0;
42 x3_min=-1.0;
43 //
44 TNtuple *nt;
45 nt= new TNtuple("nt","ntuple sample", "x1:x2:x3");
46 //
47 for(int i=0; i<1e5; i++){
48 x1=(double)rand()/RAND_MAX * (x1_max - x1_min) + x1_min;
49 y1_ref= N * exp(-(x1-mu)*(x1-mu)/(2.*sigma*sigma));
50 y1_try= (double)rand()/RAND_MAX * N;
51 //
52 x3=(double)rand()/RAND_MAX * (x1_max - x1_min) + x1_min;
53 y3_ref= N * exp(-(x3-mu)*(x3-mu)/(2.*sigma*sigma));
54 y3_try= (double)rand()/RAND_MAX * N;
55 //
56 x2=(double)rand()/RAND_MAX * (x2_max - x2_min) + x2_min;
57 //
58 if(y1_try<y1_ref && y3_try<y3_ref){
59 nt->Fill(x1, x2, x3);
60 }/* if(y_try */
61 //
62 }/* for(int i */
63
64 TFile *rootfile= new TFile("Ntuple.root","RECREATE","HogeNT output file");
65 nt->Write();
66 rootfile->Close();
67 //
68 return 0;
69 }
三次元のプロットを作ってみた。
同じようにmakeし、.rootファイルを作ってみる。
インタプリタモードでは、
root [] nt->Draw(“x1”); <enter> とか、 root [] nt->Draw(“x1:x2”); <enter> とか、 root [] nt->Draw(“x1:x2:x3”); <enter> とかとか。 root [] nt->Draw(“x1:x3”,“x1>1”); <enter> なんて、条件を引数にとることもできる。 さらに、 root [] nt->Draw(“x1:x2”, “x1>1”, “lego2”); <enter> とかとか、プロットオプションも第三引数に指定することもできるので、本当いろいろ出来るのである。
ROOTをとりあえず使う。
グラフプロットソフト,ROOTを使ってみた。
参考URLはコチラ
まずコンパイルする為のMakefile。
MakeFileにはインクルードフラグとライブラリフラグを追加しておく。
つまり、
# インクルードフラグ ROOTCFLAGS = $(shell root-config --cflags) # ライブラリリンク ROOTLIBS = $(shell root-config --libs) # (RootでGUIを作る場合のライブラリリンク) ROOTGLIBS = $(shell root-config --glibs)
をMakeFileに記述しておく。これを踏まえMakeFileは、
1: TARGETS=Hoge 2: 3: ROOTFLAGS = $(shell root-config --cflags) 4: ROOTLIBS = $(shell root-config --libs) 5: 6: CXXFLAGS = -Wall -O2 $(ROOTFLAGS) 7: CXXLIBS = $(ROOTLIBS) 8: 9: all: $(TARGETS) 10: 11: Hoget: Hoge.o 12: g++ -o $@ Hoge.o $(CXXLIBS) 13: 14: .cc.o: 15: g++ -c $(CXXFLAGS) $<
.CCのファイルは以下。
ガウス関数に従って乱数を発生させ、その分布をヒストグラムにする、というMonte-Carloシミュレーションを行っている。
1 #include "TApplication.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <math.h>
5 #include <TROOT.h>
6 #include <TStyle.h>
7 #include <TH1.h>
8 #include <TFile.h>
9
10
11 int main(int argc, char **argv){
12
13 // TApplication theApp("App", &argc, argv);
14
15 gROOT->SetStyle("Plain");
16 gStyle->SetOptStat("neiuoMR");
17 gStyle->SetPalette(1);
18
19 double N; /* factor */
20 double mu; /* mean */
21 double sigma; /* standard deviation */
22
23 double x;
24 double x_max, x_min;
25 double y_ref; /* reference value */
26 double y_try; /* trial value */
27
28 mu= 1.0;
29 sigma= 0.5;
30 N= 1./ sqrt(2.*M_PI) / sigma;
31 //
32 x_max=+3.0;
33 x_min=-1.0;
34 //
35 TH1D *h1;
36 h1= new TH1D("h1","h1 sample", 100, x_min, x_max);
37 //
38 for(int i=0; i<1e5; i++){
39 x=(double)rand()/RAND_MAX * (x_max - x_min) + x_min;
40 y_ref= N * exp(-(x-mu)*(x-mu)/(2.*sigma*sigma));
41 y_try= (double)rand()/RAND_MAX * N;
42
43 if(y_try<y_ref){
44 h1->Fill(x);
45 }
46 }
47
48 h1->SetXTitle("X-axis");
49 h1->SetYTitle("Y-axis");
50
51 // h1->Draw();
52
53 // theApp.Run();
54 TFile *f=new TFile("Hoge.root","RECREATE","Hoge_output_file");
55 h1->Write();
56 f->Close();
57
58 return 0;
59 }
60
いくつかコメントしておく。
13:includeしたTApprication.hを使ってtheAppオブジェクト作成。マクロを実行してrootfileを作成しない、即座にプロットマンガを表示する場合はこの記述と53行目のtheApp.Run();が必要になる。
15:16:17:デフォルトの形をいろいろ整える
35:一次元ヒストグラムのオブジェクトh1を定義
36:"title","graph title","bin","min","max"で指定する
48:49x軸,y軸の名前を定義
54:出力rootfileの定義"出力先ファイル名","作成オプション","メモ"
55:h1をfオブジェクトに書き込む
56:ファイルを閉じる
てな感じ。
コマンドラインで実際動かしてみる。
$ make -f Makefile g++ -c -Wall -O2 -pthread -m32 -I/usr/local/root/include Hoge.cc g++ -o Hoge Hoge.o -L/usr/local/root/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic $ ./Hoge $ ll -rwxrwxr-x 1 gauge gauge 10919 4月 25 09:11 Hoge -rw-rw-r-- 1 gauge gauge 1218 4月 25 09:11 Hoge.cc -rw-rw-r-- 1 gauge gauge 7244 4月 25 09:11 Hoge.o -rw-r--r-- 1 gauge gauge 4036 4月 25 09:11 Hoge.root
rootfileが出来てるみたい。
$ root -l Hoge.root
root h1->SetLineColor(2);
root h1->Draw();

root[] .q
いやー、面白いな。
C:エントリポイント??
関数もポインタに入れられる
1 #include <stdio.h>
2
3 int add(a,b){return a+b;}
4 int mul(a,b){return a*b;}
5
6 int main(void){
7
8 int x=39,y=12;
9 printf("%d\n",add(x,y));
10 printf("%d\n",mul(x,y));
11
12 int (*func)(int x,int y);
13 func = add;
14 printf("%d\n",(*func)(x,y));
15 func = mul;
16 printf("%d\n",(*func)(x,y));
17
18 return 0;
19 }評価順番で怒られないように(*func)と表記する。
C:値の参照引き渡し
1 #include <stdio.h>
2
3 double calc_v(double *x,double *y);
4
5 int main(void){
6
7 double a=39.0,b=12.0,sum;
8
9 //printf("&a=%p,&b=%p,&a,&b");
10
11 sum = calc_v(&a,&b);
12 printf("%f\n",sum);
13
14 return 0;
15 }
16
17 double calc_v(double *x,double *y){
18
19 double ans;
20 ans = *x + *y;
21
22 return ans;
23 }
24・3行目のプロトタイプ宣言において、引数の値もちゃんとしないと怒られた。(double,double)とか書いてた。どっかの参考書には書いてあったんだけどな。
・アドレスは%pで表記する。
・アドレスを渡してポインタにそのアドレスを代入している操作をしてる。calc_v内でそのアドレスに指定されている値を直接呼び出して関数内で使用している。こんなやり方を参照呼び出しっていうらしい。
C:ポインタを使ってみた2
1 #include <stdio.h>
2
3 void calc(int data[],int *max,int *min);
4
5 int main(void){
6
7 int i,input[10];
8 int max;
9 int min;
10
11 for(i=0;i<10;i++){
12 printf("enter the number from 1 till 100\n");
13 scanf("%d",&input[i]);
14
15 if(input[i] == -1) break;
16 }
17
18 calc(input, &max , &min);
19
20 printf("max=%d,min=%d\n",max,min);
21
22 return 0;
23 }
24
25 void calc(int data[],int *max,int *min){
26
27 int j;
28 *max = 0;
29 *min = 100;
30
31 for(j=0;j<10;j++){
32 if(data[j] > *max) *max = data[j];
33 if(data[j] < *min) *min = data[j];
34 }
35
36 return;
37 }うーん。へたくそ。
とりあえず、*dataとdata[]は一緒な気がする。
正しいのかな。
C:数式内での[]
以下、サンプル
1 #include <stdio.h>
2
3 int getaverage(int *data);
4
5 int main(void)
6 {
7 int average,array[2] = {15,78};
8
9 average = getaverage(array);
10
11 printf("%d\n",average);
12 return 0;
13 }
14
15 int getaverage(int *data)
16 {
17 int i,average = 0;
18 for (i = 0;i < 2;i++) {
19 printf("%d\n",data[i]);
20 average += data[i];
21 }
22 return average / 2;
23 }
243行目:プロトタイプ宣言 配列を変数にもらう場合はdata,ポインタ変数にもらう場合は*data
20行目: 数式内でを使う場合は、iを足すの意味でつかわれる。ここでは*(data+i)の意味である
こんな解釈だけど合ってんのかなー。。
不安になってきた。
後、ポインタって入れる変数と同じ型にしないといけない。
たぶん。そうだな。
。