0001 function [ErrorCode] = AnalyseComputationalEnvironment(DataInput, DataInputAdd)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 RemoteTmpFolder=DataInputAdd.RemoteTmpFolder;
0036 dynareParallelMkDir(RemoteTmpFolder,DataInput);
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099 ErrorCode=0;
0100
0101
0102 for Node=1:length(DataInput)
0103
0104
0105
0106
0107
0108
0109 OScallerUnix=~ispc;
0110 OScallerWindows=ispc;
0111 OStargetUnix=strcmpi('unix',DataInput(Node).OperatingSystem);
0112 if isempty(DataInput(Node).OperatingSystem),
0113 OStargetUnix=OScallerUnix;
0114 end
0115 OStargetWindows=strcmpi('windows',DataInput(Node).OperatingSystem);
0116 if isempty(DataInput(Node).OperatingSystem),
0117 OStargetWindows=OScallerWindows;
0118 end
0119
0120 Environment= (OScallerUnix || OStargetUnix);
0121
0122 disp(' ');
0123 disp(' ');
0124 disp(['Testing computer -> ',DataInput(Node).ComputerName,' <- ...']);
0125 disp(' ');
0126 disp(' ');
0127
0128
0129
0130
0131
0132
0133
0134 if ((DataInput(Node).Local == 0) |(DataInput(Node).Local == 1))
0135
0136 disp('Check on Local Variable ..... Ok!');
0137 disp(' ');
0138 disp(' ');
0139
0140 else
0141 disp('The variable "Local" has a bad value!');
0142 disp(' ');
0143 disp('ErrorCode 1.');
0144 disp(' ');
0145 disp(' ');
0146 ErrorCode=1;
0147 return
0148
0149 end
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169 if (DataInput(Node).Local == 0)
0170
0171
0172
0173
0174 si1=[];
0175 de1=[];
0176
0177 if Environment
0178 if OScallerWindows
0179 [si1 de1]=system(['ping ', DataInput(Node).ComputerName]);
0180 else
0181 [si1 de1]=system(['ping ', DataInput(Node).ComputerName, ' -c 4']);
0182 end
0183 else
0184 [si1 de1]=system(['ping ', DataInput(Node).ComputerName]);
0185 end
0186
0187 if (si1)
0188 disp(['It is impossibile to be connected to the computer with name "',DataInput(Node).ComputerName,'" using the network!']);
0189 disp(' ');
0190 disp('ErrorCode 3.');
0191 ErrorCode=3;
0192 disp(' ');
0193 disp(' ');
0194 return;
0195 else
0196 disp('Check on ComputerName Variable ..... Ok!');
0197 disp(' ');
0198 disp(' ');
0199 end
0200
0201
0202
0203
0204
0205
0206 if Environment
0207
0208
0209
0210 if (isempty(DataInput(Node).UserName))
0211 disp('The fields UserName is empty!');
0212 disp(' ');
0213 disp('ErrorCode 4.');
0214 disp(' ');
0215 disp(' ');
0216 ErrorCode=4;
0217 return
0218 end
0219 disp('Check on UserName Variable ..... Ok!');
0220 disp(' ');
0221 disp(' ');
0222
0223
0224
0225 if (~isempty(DataInput(Node).Password))
0226 disp('[WARNING] The field Password should be empty under unix or mac!');
0227 disp(' ');
0228 disp(['Remove the string ',DataInput(Node).Password,' from this field!']);
0229 disp(' ');
0230 disp('ErrorCode 4.');
0231 disp(' ');
0232 disp(' ');
0233 ErrorCode=4;
0234
0235 else
0236 disp('Check on Password Variable ..... Ok!');
0237 disp(' ');
0238 disp(' ');
0239 end
0240 else
0241
0242
0243
0244
0245 if (isempty(DataInput(Node).UserName)) || (isempty(DataInput(Node).Password))
0246 disp('The fields UserName and/or Password are/is empty!');
0247 disp(' ');
0248 disp('ErrorCode 4.');
0249 disp(' ');
0250 disp(' ');
0251 ErrorCode=4;
0252 return
0253 end
0254 disp('Check on UserName Variable ..... Ok!');
0255 disp(' ');
0256 disp(' ');
0257 disp('Check on Password Variable ..... Ok!');
0258 disp(' ');
0259 disp(' ');
0260
0261 end
0262
0263
0264
0265
0266 if Environment
0267
0268
0269
0270
0271 if isempty(DataInput(Node).RemoteDirectory)
0272 disp('The field RemoteDirectory is empty!');
0273 disp(' ');
0274 disp('ErrorCode 5.');
0275 disp(' ');
0276 disp(' ');
0277 ErrorCode=5;
0278 return
0279 end
0280
0281
0282
0283
0284 if (~isempty(DataInput(Node).RemoteDrive))
0285 disp('[WARNING] The fields RemoteDrive should be empty under unix or mac!');
0286 disp(' ');
0287 disp(['remove the string ',DataInput(Node).RemoteDrive,' from this field!']);
0288 disp(' ');
0289 disp('ErrorCode 5.');
0290 disp(' ');
0291 disp(' ');
0292 ErrorCode=5;
0293
0294 end
0295
0296 si2=[];
0297 de2=[];
0298
0299 [si2 de2]=system(['ssh ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' ls ',DataInput(Node).RemoteDirectory,'/',RemoteTmpFolder,'/']);
0300
0301 if (si2)
0302 disp ('Remote Directory does not exist or is not reachable!');
0303 disp(' ');
0304 disp('ErrorCode 5.');
0305 disp(' ');
0306 disp(' ');
0307 ErrorCode=5;
0308 return
0309 end
0310
0311 disp('Check on RemoteDirectory Variable ..... Ok!');
0312 disp(' ');
0313 disp(' ');
0314 disp('Check on RemoteDrive Variable ..... Ok!');
0315 disp(' ');
0316 disp(' ');
0317
0318 else
0319
0320
0321
0322 if (isempty(DataInput(Node).RemoteDrive)||isempty(DataInput(Node).RemoteDirectory))
0323 disp('Remote RemoteDrive and/or RemoteDirectory is/are empty!');
0324 disp(' ');
0325 disp('ErrorCode 5.');
0326 disp(' ');
0327 disp(' ');
0328 ErrorCode=5;
0329 return
0330 end
0331
0332
0333 si2=[];
0334 de2=[];
0335 [s12 de2]=system(['dir \\',DataInput(Node).ComputerName,'\',DataInput(Node).RemoteDrive,'$\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder]);
0336
0337 if (si2)
0338 disp ('Remote Directory does not exist or it is not reachable!');
0339 disp(' ');
0340 disp('ErrorCode 5.');
0341 disp(' ');
0342 disp(' ');
0343 ErrorCode=5;
0344 return
0345 end
0346
0347 disp('Check on RemoteDirectory Variable ..... Ok!');
0348 disp(' ');
0349 disp(' ');
0350 disp('Check on RemoteDrive Variable ..... Ok!');
0351 disp(' ');
0352 disp(' ');
0353
0354 end
0355
0356
0357
0358
0359
0360
0361
0362
0363 fid = fopen('Tracing.m', 'w+');
0364 s1=(['fT = fopen(''MatlabOctaveIsOk.txt'',''w+'');\n']);
0365 s2='fclose(fT);\n';
0366 SBS=strfind(DataInput(Node).DynarePath,'\');
0367 DPStr=DataInput(Node).DynarePath;
0368 if isempty(SBS),
0369 DPStrNew=DPStr;
0370 else
0371 DPStrNew=[DPStr(1:SBS(1)),'\'];
0372 for j=2:length(SBS),
0373 DPStrNew=[DPStrNew,DPStr(SBS(j-1)+1:SBS(j)),'\'];
0374 end
0375 DPStrNew=[DPStrNew,DPStr(SBS(end)+1:end)];
0376 end
0377 s3=['addpath(''',DPStrNew,'''),\n'];
0378 s4=['try,\n dynareroot = dynare_config();\n'];
0379 s41=([' fT = fopen(''DynareIsOk.txt'',''w+'');\n']);
0380 s42=' fclose(fT);\n';
0381 s5=['catch,end,\n'];
0382 s51=([' fT = fopen(''DynareFailed.txt'',''w+'');\n']);
0383 s52=' fclose(fT);\n';
0384 send='exit';
0385 StrCommand=([s1,s2,s3,s4,s41,s42,s5,s51,s52,send]);
0386
0387
0388
0389
0390
0391 NbW = fprintf(fid,StrCommand, '%s');
0392
0393 fclose(fid);
0394
0395 dynareParallelSendFiles('Tracing.m', RemoteTmpFolder,DataInput(Node));
0396 FindTracing = dynareParallelDir('Tracing.m', RemoteTmpFolder,DataInput(Node));
0397
0398 delete ('Tracing.m');
0399
0400 if (isempty(FindTracing))
0401 disp ('It is impossible to exchange data with Remote Drive and/or Remote Directory! ErrorCode 6.');
0402 disp(' ');
0403 disp('ErrorCode 6.');
0404 disp(' ');
0405 disp(' ');
0406 ErrorCode=6;
0407 return
0408 else
0409 disp('Check on Exchange File with Remote Computer ..... Ok!');
0410 disp(' ');
0411 disp(' ');
0412 end
0413
0414
0415
0416
0417
0418
0419 if Environment
0420 if strfind([DataInput(Node).MatlabOctavePath], 'octave')
0421 system(['ssh ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' "cd ',DataInput(Node).RemoteDirectory,'/',RemoteTmpFolder, '; ', DataInput(Node).MatlabOctavePath, ' Tracing.m;" &']);
0422 else
0423 system(['ssh ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' "cd ',DataInput(Node).RemoteDirectory,'/',RemoteTmpFolder, '; ', DataInput(Node).MatlabOctavePath, ' -nosplash -nodesktop -minimize -r Tracing;" &']);
0424 end
0425 else
0426 if strfind([DataInput(Node).MatlabOctavePath], 'octave')
0427 [NonServeS NenServeD]=system(['start /B psexec \\',DataInput(Node).ComputerName,' -e -u ',DataInput(Node).UserName,' -p ',DataInput(Node).Password,' -W ',DataInput(Node).RemoteDrive,':\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder ' -low ',DataInput(Node).MatlabOctavePath,' Tracing.m']);
0428 else
0429 [NonServeS NenServeD]=system(['start /B psexec \\',DataInput(Node).ComputerName,' -e -u ',DataInput(Node).UserName,' -p ',DataInput(Node).Password,' -W ',DataInput(Node).RemoteDrive,':\',DataInput(Node).RemoteDirectory,'\',RemoteTmpFolder ' -low ',DataInput(Node).MatlabOctavePath,' -nosplash -nodesktop -minimize -r Tracing']);
0430 end
0431 end
0432
0433
0434
0435 t1=fix(clock);
0436
0437 if t1(5)+1>60;
0438 t2=2;
0439 else t2=t1(5)+1;
0440 end
0441
0442 Flag=0;
0443
0444 while (1);
0445 if Flag==0
0446 disp('Try to run matlab/octave on remote machine ... ');
0447 disp(' ');
0448 disp('please wait ... ');
0449 disp(' ');
0450 Flag=1;
0451 end
0452 nt=fix(clock);
0453 nt(5)-t2;
0454
0455 if (~isempty (dynareParallelDir('MatlabOctaveIsOk.txt',RemoteTmpFolder,DataInput(Node)))) || ((nt(5)-t2)>0)
0456 if ((nt(5)-t2)>0)
0457 ErrorCode=7;
0458 end
0459 break
0460 end
0461
0462 end
0463
0464 if (ErrorCode==7)
0465
0466 disp ('It is not possible execute a matlab session on remote machine!');
0467 disp(' ');
0468 disp('ErrorCode 7.');
0469 disp(' ');
0470 disp(' ');
0471 ErrorCode=7;
0472 dynareParallelRmDir(RemoteTmpFolder,DataInput(Node));
0473 return
0474
0475 else
0476 disp('Check on MatlabOctave Path and MatlabOctave Program Execution on remote machine ..... Ok!');
0477 disp(' ');
0478 disp(' ');
0479
0480
0481 disp('Check the Dynare path on remote machine ... ');
0482 disp(' ');
0483 disp('please wait ... ');
0484 disp(' ');
0485 pause(2)
0486
0487 if isempty(dynareParallelDir('DynareIsOk.txt',RemoteTmpFolder,DataInput(Node)))
0488 ErrorCode=8;
0489 end
0490
0491 if (ErrorCode==8)
0492
0493 disp ('The DynarePath is incorrect!');
0494 disp(' ');
0495 disp('ErrorCode 8.');
0496 disp(' ');
0497 disp(' ');
0498 ErrorCode=8;
0499 dynareParallelRmDir(RemoteTmpFolder,DataInput(Node));
0500 return
0501
0502 else
0503 disp('Check on Dynare Path remote machine ..... Ok!');
0504 disp(' ');
0505 disp(' ');
0506 end
0507 end
0508
0509
0510
0511
0512 dynareParallelRmDir(RemoteTmpFolder,DataInput(Node));
0513
0514 si3=[];
0515
0516 si3=dynareParallelDir('Tracing.m', RemoteTmpFolder,DataInput(Node));
0517
0518 if (isempty(si3))
0519 disp ('Check on Delete Remote Computational Traces ..... Ok!');
0520 disp(' ');
0521 disp(' ');
0522 else
0523 disp ('It is impossible to delete temporary files on remote machine!');
0524 disp(' ');
0525 disp('ErrorCode 9.');
0526 disp(' ');
0527 disp(' ');
0528 ErrorCode=9;
0529 return
0530 end
0531
0532
0533 end
0534
0535
0536
0537
0538
0539 yn=isempty(DataInput(Node).CPUnbr);
0540
0541 if yn==1
0542
0543 disp('The field "CPUnbr" is empty!');
0544 disp(' ');
0545 disp('ErrorCode 2.');
0546 disp(' ');
0547 disp(' ');
0548 ErrorCode=2;
0549 return
0550 end
0551
0552
0553
0554
0555
0556
0557
0558
0559 si0=[];
0560 de0=[];
0561
0562 disp('Checking Hardware please wait ...');
0563 if (DataInput(Node).Local == 1)
0564 if Environment,
0565 [si0 de0]=system('grep processor /proc/cpuinfo');
0566 else
0567 [si0 de0]=system(['psinfo \\']);
0568 end
0569 else
0570 if Environment,
0571 if OStargetUnix,
0572 [si0 de0]=system(['ssh ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' grep processor /proc/cpuinfo']);
0573 else
0574 [si0 de0]=system(['ssh ',DataInput(Node).UserName,'@',DataInput(Node).ComputerName,' psinfo']);
0575 end
0576 else
0577 [si0 de0]=system(['psinfo \\',DataInput(Node).ComputerName,' -u ',DataInput(Node).UserName,' -p ',DataInput(Node).Password]);
0578 end
0579 end
0580
0581
0582 RealCPUnbr='';
0583
0584 RealCPUnbr=GiveCPUnumber(de0,OStargetUnix);
0585
0586
0587 if isempty (RealCPUnbr) && Environment==0,
0588 [si0 de0]=system(['psinfo \\',DataInput(Node).ComputerName]);
0589 end
0590 RealCPUnbr=GiveCPUnumber(de0,OStargetUnix);
0591
0592 if isempty (RealCPUnbr)
0593
0594
0595 disp('It is impossible determine the number of Cpu/Processor avaiable on this machine!');
0596 disp(' ');
0597 disp('ErrorCode 2.');
0598 disp(' ');
0599 if Environment
0600 disp('Check the command "$less /proc/cpuinfo" ... !');
0601 else
0602 disp('Check if the pstools are installed and are in machine path! And check the command "psinfo \\"');
0603 end
0604 disp(' ');
0605 ErrorCode=2;
0606 return
0607 end
0608
0609
0610
0611
0612
0613
0614 CPUnbrUser=length(DataInput(Node).CPUnbr);
0615 maxCPUnbrUser=max(DataInput(Node).CPUnbr)+1;
0616
0617 disp(['Hardware has ', num2str(RealCPUnbr),' Cpu/Cores!']);
0618 disp(['User requires ',num2str(CPUnbrUser),' Cpu/Cores!']);
0619 if CPUnbrUser==RealCPUnbr,
0620
0621 disp('Check on CPUnbr Variable ..... Ok!');
0622 disp(' ');
0623 disp(' ');
0624 disp(' ');
0625
0626 end
0627
0628 if CPUnbrUser > RealCPUnbr
0629 disp('Warning! The user asks to use more CPU''s than those available.');
0630 disp(' ');
0631 disp(' ');
0632 ErrorCode=2.1;
0633
0634
0635 end
0636 if CPUnbrUser < RealCPUnbr
0637 disp('Warning! There are unused CPU''s!');
0638 disp(' ');
0639 disp(' ');
0640 ErrorCode=2.2;
0641
0642 end
0643
0644 disp(['Test for Cluster computation, computer ',DataInput(Node).ComputerName, ' ..... Passed!']);
0645 disp(' ');
0646 disp(' ');
0647
0648
0649 end
0650
0651 return