submitParallelFlowJobs.pl 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #! /opt/star/bin/perl -w
  2. $help =<<"EOF";
  3. usage: $0 --f=
  4. --f, the configuration file of a job.
  5. EOF
  6. use Cwd 'abs_path'; # aka realpath()
  7. use Getopt::Long;
  8. GetOptions( "f=s" => \$configFile );
  9. die $help," Pl. specify the configuration file."
  10. unless defined $configFile;
  11. # read in config file
  12. open (CONFIG, "< $configFile") or die "can't open $configFile $!";
  13. while (<CONFIG>){
  14. chomp; # no newline
  15. s/#.*//; # no comments
  16. s/^\s+//; # no leading white
  17. s/\s+$//; # no trailing white
  18. next unless length; # anything left?
  19. my ($var, $value) = split (/\s*:\s*/, $_,2);
  20. $ConfigMap{$var} = $value;
  21. }
  22. close(CONFIG);
  23. @flowCents = (
  24. "cen1", # do not change these names
  25. "cen2",
  26. "cen3",
  27. "cen4",
  28. "cen5",
  29. "cen6",
  30. "cen7",
  31. "cen8"
  32. );
  33. my $macroName = $ConfigMap{"macroName"};
  34. my $libVersion = $ConfigMap{"libVersion"};
  35. my $runJob = $ConfigMap{"scriptName"};
  36. my $jobPrefix = $ConfigMap{"partnPrefix"};
  37. my $picoDstLink = $ConfigMap{"picoDSTLink"};
  38. my $NPartition = $ConfigMap{"NPartition"};
  39. my $jobDir = $ConfigMap{"jobDir"};
  40. my $jobName = $ConfigMap{"jobName"};
  41. my $dataDir = $ConfigMap{"dataDir"};
  42. my $logFile = $ConfigMap{"logFileName"};
  43. # get a list of all flow pico dsts
  44. @totalList=glob($dataDir."/*.root");
  45. # get number of files for one partition.
  46. $NFilesInOnePartition = int(scalar(@totalList)/$NPartition);
  47. # make job directories
  48. print `mkdir $jobDir/$jobName`;
  49. # copying source code to $jobName
  50. print `cp -r $jobDir/StRoot $jobDir/$jobName`;
  51. print `cp $configFile $jobDir/$jobName/$configFile`;
  52. # cons
  53. my $consFileName="consDir";
  54. open ( consScript, ">".$consFileName.".csh");
  55. print consScript "#!/bin/csh \n";
  56. print consScript "cd $jobDir/$jobName \n";
  57. print consScript "source /auto/u/aihong/.starver $libVersion \n";
  58. print consScript "cons \n";
  59. close consScript;
  60. print "$consFileName.csh has been generated \n";
  61. print "now run $consFileName.csh : \n";
  62. print `csh -x $jobDir/$consFileName.csh`;
  63. print `rm $jobDir/$consFileName.csh`;
  64. # making directories for partitioned jobs
  65. for ($m=1; $m<$NPartition+1; $m++) {
  66. print `mkdir $jobDir/$jobName/$jobPrefix$m`;
  67. print `mkdir $jobDir/$jobName/$jobPrefix$m/$picoDstLink`; # dir for picoDST links for a partition
  68. my @END;
  69. if ($m <$NPartition) {
  70. @END=splice(@totalList, -$NFilesInOnePartition) #pop up NFilesInOnePartition files
  71. } else {@END=@totalList;} # the last partition.
  72. # making links to pico dst
  73. foreach $eachFile (@END) {
  74. ($stripped = $eachFile) =~ s/$dataDir//; #now $dataDir begin with "/"
  75. print `ln -s $eachFile $jobDir/$jobName/$jobPrefix$m/$picoDstLink$stripped \n`;
  76. }
  77. # making centrality directories, and lib links
  78. foreach $cent(@flowCents) {
  79. print `mkdir $jobDir/$jobName/$jobPrefix$m/$cent`;
  80. print `ln -s $jobDir/$jobName/.share $jobDir/$jobName/$jobPrefix$m/$cent/.share \n`;
  81. print `ln -s $jobDir/$jobName/.i386_redhat61 $jobDir/$jobName/$jobPrefix$m/$cent/.i386_redhat61 \n`;
  82. # producing macro
  83. open (macroFile,">$jobDir/$jobName/$jobPrefix$m/$cent/$macroName");
  84. open (prototypeMacro,$jobDir."/doFlowEvents.C");
  85. while ($eachLine = <prototypeMacro>) {
  86. if ($eachLine=~/SetCent/) {
  87. if ($cent=~/cen1/){$eachLine=" StFlowCutEvent::SetCent(1, 1); \n";}
  88. if ($cent=~/cen2/){$eachLine=" StFlowCutEvent::SetCent(2, 2); \n";}
  89. if ($cent=~/cen3/){$eachLine=" StFlowCutEvent::SetCent(3, 3); \n";}
  90. if ($cent=~/cen4/){$eachLine=" StFlowCutEvent::SetCent(4, 4); \n";}
  91. if ($cent=~/cen5/){$eachLine=" StFlowCutEvent::SetCent(5, 5); \n";}
  92. if ($cent=~/cen6/){$eachLine=" StFlowCutEvent::SetCent(6, 6); \n";}
  93. if ($cent=~/cen7/){$eachLine=" StFlowCutEvent::SetCent(7, 7); \n";}
  94. if ($cent=~/cen8/){$eachLine=" StFlowCutEvent::SetCent(8, 8); \n";}
  95. }
  96. print macroFile $eachLine;
  97. }
  98. close macroFile;
  99. close prototypeMacro;
  100. # producing shell script
  101. open (shellScript,">$jobDir/$jobName/$jobPrefix$m/$cent/$runJob");
  102. print shellScript "#! /bin/csh \n";
  103. print shellScript "#BSUB -J $jobName/$jobPrefix$m/$cent \n";
  104. print shellScript "#BSUB -u aihong\@cnr2.kent.edu\n";
  105. print shellScript "set logfile=$logFile \n";
  106. print shellScript "set rundir=$jobDir/$jobName/$jobPrefix$m/$cent \n";
  107. print shellScript "\n";
  108. print shellScript "cd \$rundir \n";
  109. print shellScript "source /auto/u/aihong/.starver $libVersion \n";
  110. print shellScript "root4star -b << EOF >>\& \$logfile \n";
  111. print shellScript ".which doFlowEvents.C \n";
  112. print shellScript ".x doFlowEvents.C(1000000,\"$jobDir/$jobName/$jobPrefix$m/$picoDstLink\",\"*flowpicoevent.root\") \n";
  113. print shellScript ".q \n";
  114. print shellScript "EOF \n";
  115. print shellScript "exit 0 \n";
  116. close shellScript;
  117. }
  118. }
  119. for ($m=1; $m<$NPartition+1; $m++) {
  120. foreach $cent(@flowCents) {
  121. # print `bsub -q medium -R "linux select[defined(dv36io)] rusage[dv36io=50]" < $jobDir/$jobName/$jobPrefix$m/$cent/$runJob`;
  122. print `bsub -q medium < $jobDir/$jobName/$jobPrefix$m/$cent/$runJob`;
  123. # print "$jobDir/$jobName/$jobPrefix$m/$cent/$runJob \n";
  124. }
  125. }
  126. exit;
  127. #perl parallFlowJobSubmit.pl --d /auto/pdsfdv36/starebye/aihong/MinbiasP01hi/copiedFromPdsfdv08 --i 5 --o test
  128. ####$pwd = abs_path ( $ENV { 'PWD' } );