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

Last change on this file since 11995 was 11995, checked in by Mathieu Morlighem, 13 years ago

merged trunk-jpl and trunk for revision 11994M

File size: 7.0 KB
RevLine 
[8586]1%GENERIC cluster class definition
[8578]2%
3% Usage:
[8586]4% cluster=generic('name','astrid',);
5% cluster=generic('name','astrid','np',3);
6% cluster=generic('name',oshostname(),'np',3,'login','username');
[8578]7
8classdef generic
9 properties (SetAccess=public)
10 % {{{1
[8586]11 name='';
[8578]12 login='';
[8586]13 np=1;
[8578]14 port=0;
15 interactive=1;
16 codepath=[issmtier() '/bin'];
[10945]17 executionpath=[issmtier() '/execution'];
[8578]18 valgrind=[issmtier() '/externalpackages/valgrind/install/bin/valgrind'];
19 valgrindlib=[issmtier() '/externalpackages/valgrind/install/lib/libmpidebug.so'];
20 valgrindsup=[issmtier() '/externalpackages/valgrind/issm.supp'];
21 %}}}
22 end
23 methods
24 function cluster=generic(varargin) % {{{1
[8586]25
26 %use provided options to change fields
27 options=pairoptions(varargin{:});
28
29 %get name
30 if ~exist(options,'name'), error('option ''name'' has not been provided'); end
31 cluster.name=getfieldvalue(options,'name');
32
[8578]33 %initialize cluster using user settings if provided
[8583]34 if (exist([cluster.name '_settings'])==2), eval([cluster.name '_settings']); end
[8578]35
[8586]36 %OK get other fields
[11995]37 cluster=AssignObjectFields(pairoptions(varargin{:}),cluster);
[8578]38 end
39 %}}}
40 function disp(cluster) % {{{1
41 % display the object
42 disp(sprintf('class ''%s'' object ''%s'' = ',class(cluster),inputname(1)));
43 disp(sprintf(' name: %s',cluster.name));
44 disp(sprintf(' login: %s',cluster.login));
45 disp(sprintf(' np: %i',cluster.np));
46 disp(sprintf(' port: %i',cluster.port));
47 disp(sprintf(' codepath: %s',cluster.codepath));
48 disp(sprintf(' executionpath: %s',cluster.executionpath));
49 disp(sprintf(' valgrind: %s',cluster.valgrind));
50 disp(sprintf(' valgrindlib: %s',cluster.valgrindlib));
51 disp(sprintf(' valgrindsup: %s',cluster.valgrindsup));
52 end
53 %}}}
[9853]54 function checkconsistency(cluster,md,solution,analyses) % {{{1
[8586]55 if cluster.np<1
[9751]56 checkmessage(['number of processors should be at least 1']);
[8578]57 end
58 if isnan(cluster.np),
[9751]59 checkessage('number of processors should not be NaN!');
[8578]60 end
61 end
62 %}}}
63 function BuildQueueScript(cluster,md) % {{{1
64
65 %retrieve parameters
[9625]66 modelname=md.miscellaneous.name;
[9853]67 solution=md.private.solution;
[9565]68 isvalgrind=md.debug.valgrind;
69 isgprof=md.debug.gprof;
[8578]70
71 %open file for writing:
[11527]72 if ~ispc,
73 fid=fopen([modelname '.queue'],'w');
74 else
75 fid=fopen([modelname '.bat'],'w');
76 end
[8578]77
78 %write instructions for launching a job on the cluster
[11527]79 if ~ispc,
80 fprintf(fid,'#!/bin/sh\n');
81 else
82 fprintf(fid,'@echo off\n');
83 end
84
[9565]85 if ~isvalgrind,
[8578]86 if cluster.interactive
[11527]87 if ~ispc,
88 fprintf(fid,'mpiexec -np %i %s/issm.exe %s %s %s ',cluster.np,cluster.codepath,EnumToString(solution),cluster.executionpath,modelname);
89 else
90 fprintf(fid,'"%s/issm.exe" %s "%s" %s ',cluster.codepath,EnumToString(solution),cluster.executionpath,modelname);
91 end
[8578]92 else
[11527]93 if ~ispc,
94 fprintf(fid,'mpiexec -np %i %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',cluster.np,cluster.codepath,EnumToString(solution),cluster.executionpath,modelname,modelname,modelname);
95 else
96 fprintf(fid,'"%s/issm.exe" %s "%s" %s 2> %s.errlog >%s.outlog ',cluster.codepath,EnumToString(solution),cluster.executionpath,modelname,modelname,modelname);
97 end
[8578]98 end
99 else
[11527]100 if ~ispc,
101 %Add --gen-suppressions=all to get suppression lines
102 fprintf(fid,'LD_PRELOAD=%s \\\n',cluster.valgrindlib);
103 fprintf(fid,'mpiexec -np %i %s --leak-check=full --suppressions=%s %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',...
[11237]104 cluster.np,cluster.valgrind,cluster.valgrindsup, cluster.codepath,EnumToString(solution),cluster.executionpath,modelname,modelname,modelname);
[11527]105 else
106 error('valgrind not supported on windows platforms');
107 end
[8578]108 end
109
[9565]110 if isgprof,
[11527]111 if ~ispc,
112 fprintf(fid,'\n gprof %s/issm.exe gmon.out > %s.performance',cluster.codepath,modelname);
113 else
114 error('gprof not supported on windows platforms');
115 end
116
[8578]117 end
118
[9622]119 if ~md.settings.io_gather,
[11527]120 if ~ispc,
121 %concatenate the output files:
122 fprintf(fid,'\ncat %s.outbin.* > %s.outbin',modelname,modelname);
123 else
124 error('iogather not supported on windows platforms');
125 end
126
[8578]127 end
[11527]128
129 %close file:
130 fclose(fid);
[8578]131
132 %in interactive mode, create a run file, and errlog and outlog file
133 if cluster.interactive,
134 fid=fopen([modelname '.errlog'],'w'); fclose(fid);
135 fid=fopen([modelname '.outlog'],'w'); fclose(fid);
136 end
137
[11527]138
[8578]139 end
140 %}}}
141 function LaunchQueueJob(cluster,md,options)% {{{1
142
[11527]143 if ~ispc,
144 %lauch command, to be executed via ssh
145 launchcommand=['cd ' cluster.executionpath ' && rm -rf ./' md.private.runtimename ' && mkdir ' md.private.runtimename ...
146 ' && cd ' md.private.runtimename ' && mv ../' md.private.runtimename '.tar.gz ./ && tar -zxf ' md.private.runtimename '.tar.gz && source ' md.miscellaneous.name '.queue '];
[8578]147
[11527]148 if ~strcmpi(options.batch,'yes'),
149
150 %compress the files into one zip.
151 compressstring=['tar -zcf ' md.private.runtimename '.tar.gz ' md.miscellaneous.name '.bin ' md.miscellaneous.name '.queue ' md.miscellaneous.name '.petsc '];
152 if md.qmu.isdakota,
153 compressstring=[compressstring md.miscellaneous.name '.qmu.in'];
154 end
155 if cluster.interactive,
156 compressstring=[compressstring ' ' md.miscellaneous.name '.errlog ' md.miscellaneous.name '.outlog '];
157 end
158 system(compressstring);
159
160 disp('uploading input file and queueing script');
161 issmscpout(cluster.name,cluster.executionpath,cluster.login,cluster.port,{[md.private.runtimename '.tar.gz']});
162
163 disp('launching solution sequence on remote cluster');
164 issmssh(cluster.name,cluster.login,cluster.port,launchcommand);
165 else
166 disp('batch mode requested: not launching job interactively');
167 disp('launch solution sequence on remote cluster by hand');
[8578]168 end
169 else
[11527]170 %launch right here, do not compress or archive.
171 system([md.miscellaneous.name '.bat']);
[8578]172 end
173
[11527]174 end %}}}
[8578]175 function Download(cluster,md)% {{{1
176
[11527]177 if ~ispc,
178 %some check
179 if isempty(md.private.runtimename),
180 error('supply runtime name for results to be loaded!');
181 end
[8578]182
[11527]183 %Figure out the directory where all the files are in:
184 directory=[cluster.executionpath '/' md.private.runtimename '/'];
[8578]185
[11527]186 %What packages are we picking up from remote cluster
187 packages={[md.miscellaneous.name '.outlog'],[md.miscellaneous.name '.errlog']};
188 if md.qmu.isdakota,
189 packages{end+1}=[md.miscellaneous.name '.qmu.err'];
190 packages{end+1}=[md.miscellaneous.name '.qmu.out'];
191 if isfield(md.qmu.params,'tabular_graphics_data'),
192 if md.qmu.params.tabular_graphics_data==true,
193 packages{end+1}='dakota_tabular.dat';
194 end
[8578]195 end
[11527]196 else
197 packages{end+1}=[md.miscellaneous.name '.outbin'];
[8578]198 end
[11527]199
200 %copy files from cluster to present directory
201 issmscpin(cluster.name, cluster.login, cluster.port, directory, packages);
[8578]202 else
[11527]203 %do nothing!
[8578]204 end
205 end %}}}
206 end
207end
Note: See TracBrowser for help on using the repository browser.