source: issm/trunk/src/m/classes/clusters/generic.m@ 16137

Last change on this file since 16137 was 16137, checked in by Mathieu Morlighem, 12 years ago

merged trunk-jpl and trunk for revision 16135

File size: 8.5 KB
RevLine 
[8586]1%GENERIC cluster class definition
[8578]2%
3% Usage:
[8586]4% cluster=generic('name','astrid','np',3);
5% cluster=generic('name',oshostname(),'np',3,'login','username');
[8578]6
7classdef generic
[13395]8 properties (SetAccess=public)
9 % {{{
10 name='';
11 login='';
12 np=1;
13 port=0;
14 interactive=1;
15 codepath=[issmdir() '/bin'];
[13975]16 etcpath=[issmdir() '/etc'];
[13395]17 executionpath=[issmdir() '/execution'];
18 valgrind=[issmdir() '/externalpackages/valgrind/install/bin/valgrind'];
19 valgrindlib=[issmdir() '/externalpackages/valgrind/install/lib/libmpidebug.so'];
20 valgrindsup=[issmdir() '/externalpackages/valgrind/issm.supp'];
21 %}}}
22 end
23 methods
24 function cluster=generic(varargin) % {{{
[8586]25
[13395]26 %use provided options to change fields
27 options=pairoptions(varargin{:});
[8586]28
[13395]29 %get name
30 cluster.name=getfieldvalue(options,'name',oshostname());
[8586]31
[13395]32 %initialize cluster using user settings if provided
33 if (exist([cluster.name '_settings'])==2), eval([cluster.name '_settings']); end
[8578]34
[13395]35 %OK get other fields
36 cluster=AssignObjectFields(pairoptions(varargin{:}),cluster);
37 end
38 %}}}
39 function disp(cluster) % {{{
40 % display the object
41 disp(sprintf('class ''%s'' object ''%s'' = ',class(cluster),inputname(1)));
42 disp(sprintf(' name: %s',cluster.name));
43 disp(sprintf(' login: %s',cluster.login));
44 disp(sprintf(' np: %i',cluster.np));
45 disp(sprintf(' port: %i',cluster.port));
46 disp(sprintf(' codepath: %s',cluster.codepath));
47 disp(sprintf(' executionpath: %s',cluster.executionpath));
[13975]48 disp(sprintf(' etcpath: %s',cluster.executionpath));
[13395]49 disp(sprintf(' valgrind: %s',cluster.valgrind));
50 disp(sprintf(' valgrindlib: %s',cluster.valgrindlib));
51 disp(sprintf(' valgrindsup: %s',cluster.valgrindsup));
52 end
53 %}}}
54 function md = checkconsistency(cluster,md,solution,analyses) % {{{
55 if cluster.np<1
56 md = checkmessage(md,['number of processors should be at least 1']);
57 end
58 if isnan(cluster.np),
59 md = checkmessage(md,'number of processors should not be NaN!');
60 end
61 end
62 %}}}
63 function BuildQueueScript(cluster,dirname,modelname,solution,io_gather,isvalgrind,isgprof) % {{{
[8578]64
[13395]65 %write queuing script
66 if ~ispc(),
[12706]67
[13395]68 fid=fopen([modelname '.queue'],'w');
69 fprintf(fid,'#!/bin/sh\n');
70 if ~isvalgrind,
71 if cluster.interactive
[16137]72 if IssmConfig('_HAVE_MPI_'),
[13395]73 fprintf(fid,'mpiexec -np %i %s/issm.exe %s %s %s ',cluster.np,cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname],modelname);
74 else
75 fprintf(fid,'%s/issm.exe %s %s %s ',cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname],modelname);
76 end
77 else
[16137]78 if IssmConfig('_HAVE_MPI_'),
[13395]79 fprintf(fid,'mpiexec -np %i %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',cluster.np,cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname],modelname,modelname,modelname);
80 else
81 fprintf(fid,'%s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname],modelname,modelname,modelname);
82 end
83 end
84 elseif isgprof,
85 fprintf(fid,'\n gprof %s/issm.exe gmon.out > %s.performance',cluster.codepath,modelname);
86 else
87 %Add --gen-suppressions=all to get suppression lines
88 fprintf(fid,'LD_PRELOAD=%s \\\n',cluster.valgrindlib);
89 if ismac,
[16137]90 if IssmConfig('_HAVE_MPI_'),
[13395]91 fprintf(fid,'mpiexec -np %i %s --leak-check=full --dsymutil=yes --suppressions=%s %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',...
92 cluster.np,cluster.valgrind,cluster.valgrindsup,cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname], modelname,modelname,modelname);
93 else
94 fprintf(fid,'%s --leak-check=full --dsymutil=yes --suppressions=%s %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',...
95 cluster.valgrind,cluster.valgrindsup,cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname], modelname,modelname,modelname);
96 end
97 else
[16137]98 if IssmConfig('_HAVE_MPI_'),
[13395]99 fprintf(fid,'mpiexec -np %i %s --leak-check=full --suppressions=%s %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',...
100 cluster.np,cluster.valgrind,cluster.valgrindsup,cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname],modelname,modelname,modelname);
101 else
102 fprintf(fid,'%s --leak-check=full --suppressions=%s %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',...
103 cluster.valgrind,cluster.valgrindsup,cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname],modelname,modelname,modelname);
104 end
105 end
106 end
107 if ~io_gather, %concatenate the output files:
108 fprintf(fid,'\ncat %s.outbin.* > %s.outbin',modelname,modelname);
109 end
110 fclose(fid);
[12706]111
[13395]112 else % Windows
[12706]113
[13395]114 fid=fopen([modelname '.bat'],'w');
115 fprintf(fid,'@echo off\n');
[15396]116
117 if cluster.np>1,
118 fprintf(fid,'"C:\\Program Files\\MPICH2\\bin\\mpiexec.exe" -n %i "%s/issm.exe" %s ./ %s ',cluster.np,cluster.codepath,EnumToString(solution),modelname);
[13395]119 else
[15396]120 fprintf(fid,'"%s/issm.exe" %s ./ %s ',cluster.codepath,EnumToString(solution),modelname);
[13395]121 end
122 fclose(fid);
123 end
[8578]124
[13395]125 %in interactive mode, create a run file, and errlog and outlog file
126 if cluster.interactive,
127 fid=fopen([modelname '.errlog'],'w'); fclose(fid);
128 fid=fopen([modelname '.outlog'],'w'); fclose(fid);
129 end
130 end
131 %}}}
132 function BuildKrigingQueueScript(cluster,modelname,solution,io_gather,isvalgrind,isgprof) % {{{
[12706]133
[13395]134 %write queuing script
135 if ~ispc(),
[12706]136
[13395]137 fid=fopen([modelname '.queue'],'w');
138 fprintf(fid,'#!/bin/sh\n');
139 if ~isvalgrind,
140 if cluster.interactive
141 fprintf(fid,'mpiexec -np %i %s/kriging.exe %s %s ',cluster.np,cluster.codepath,[cluster.executionpath '/' modelname],modelname);
142 else
143 fprintf(fid,'mpiexec -np %i %s/kriging.exe %s %s 2> %s.errlog >%s.outlog ',cluster.np,cluster.codepath,[cluster.executionpath '/' modelname],modelname,modelname,modelname);
144 end
145 elseif isgprof,
146 fprintf(fid,'\n gprof %s/kriging.exe gmon.out > %s.performance',cluster.codepath,modelname);
147 else
148 %Add --gen-suppressions=all to get suppression lines
149 fprintf(fid,'LD_PRELOAD=%s \\\n',cluster.valgrindlib);
150 fprintf(fid,'mpiexec -np %i %s --leak-check=full --suppressions=%s %s/kriging.exe %s %s 2> %s.errlog >%s.outlog ',...
151 cluster.np,cluster.valgrind,cluster.valgrindsup,cluster.codepath,[cluster.executionpath '/' modelname],modelname,modelname,modelname);
152 end
153 if ~io_gather, %concatenate the output files:
154 fprintf(fid,'\ncat %s.outbin.* > %s.outbin',modelname,modelname);
155 end
156 fclose(fid);
[11527]157
[13395]158 else % Windows
[8578]159
[13395]160 fid=fopen([modelname '.bat'],'w');
161 fprintf(fid,'@echo off\n');
162 if cluster.interactive
163 fprintf(fid,'"%s/issm.exe" %s "%s" %s ',cluster.codepath,EnumToString(solution),[cluster.executionpath '/' modelname],modelname);
164 else
165 fprintf(fid,'"%s/issm.exe" %s "%s" %s 2> %s.errlog >%s.outlog',...
166 cluster.codepath,EnumToString(solution),[cluster.executionpath '/' modelname],modelname,modelname,modelname);
167 end
168 fclose(fid);
169 end
[8578]170
[13395]171 %in interactive mode, create a run file, and errlog and outlog file
172 if cluster.interactive,
173 fid=fopen([modelname '.errlog'],'w'); fclose(fid);
174 fid=fopen([modelname '.outlog'],'w'); fclose(fid);
175 end
176 end
177 %}}}
178 function LaunchQueueJob(cluster,modelname,dirname,filelist)% {{{
[8578]179
[15396]180 if ~ispc,
181 %compress the files into one zip.
182 compressstring=['tar -zcf ' dirname '.tar.gz '];
183 for i=1:numel(filelist),
184 compressstring = [compressstring ' ' filelist{i}];
185 end
186 if cluster.interactive,
187 compressstring = [compressstring ' ' modelname '.errlog ' modelname '.outlog '];
188 end
189 system(compressstring);
[11527]190
[15396]191 disp('uploading input file and queueing script');
192 issmscpout(cluster.name,cluster.executionpath,cluster.login,cluster.port,{[dirname '.tar.gz']});
[11527]193
[15396]194 disp('launching solution sequence on remote cluster');
195 launchcommand=['source ' cluster.etcpath '/environment.sh && cd ' cluster.executionpath ' && rm -rf ./' dirname ' && mkdir ' dirname ...
196 ' && cd ' dirname ' && mv ../' dirname '.tar.gz ./ && tar -zxf ' dirname '.tar.gz && source ' modelname '.queue '];
197 issmssh(cluster.name,cluster.login,cluster.port,launchcommand);
198 else
199 system([modelname '.bat']);
200 end
[13395]201 end %}}}
202 function Download(cluster,dirname,filelist)% {{{
[11527]203
[13395]204 if ispc(),
[12706]205 %do nothing
206 return;
[8578]207 end
208
[12706]209 %copy files from cluster to current directory
210 directory=[cluster.executionpath '/' dirname '/'];
211 issmscpin(cluster.name,cluster.login,cluster.port,directory,filelist);
[11527]212 end %}}}
[8578]213 end
214end
Note: See TracBrowser for help on using the repository browser.