Skip to content

Commit

Permalink
svn path=/trunk/boinc/; revision=25537
Browse files Browse the repository at this point in the history
  • Loading branch information
Wenjing Wu committed Apr 9, 2012
1 parent a3533b9 commit 96b549e
Showing 1 changed file with 90 additions and 61 deletions.
151 changes: 90 additions & 61 deletions html/user/lammps.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
require_once("../inc/util.inc");
require_once("../inc/submit_db.inc");
require_once("../inc/sandbox.inc");
$debug=0;

// test a LAMMPS job
//
Expand All @@ -35,15 +36,23 @@ function lammps_est() {
$descs = array();
$pipes = array();
$options = file("cmd_variables");
$cmd = "../lmp_linux ".$options[0];
//echo $cmd;
$options[0]=chop($options[0],"\n");
$cmd = "../lmp_linux ".$options[0]."&>output";
if($GLOBALS["debug"]) echo $cmd."<br>";
system("unzip pot_files >/dev/null");
$stime=time();
$p = proc_open("$cmd", $descs, $pipes);
system("unzip pot.zip");
while (1) {
$ctime=time();
if($ctime-$stime >=2 and ! file_exists("log.1")){
if($GLOBALS["debug"]) echo "time out "."<br>";
proc_terminate($p);
break;
}
if (file_exists("log.1")) {
$avg_cpu = calc_step_cpu("log.1");
if ($avg_cpu != 0) {
//echo "avg_cpu is ".$avg_cpu."\n";
if($GLOBALS["debug"])echo "avg_cpu is ".$avg_cpu."<br>";
proc_terminate($p);
$test_result = 1;
break;
Expand Down Expand Up @@ -83,10 +92,54 @@ function get_total_steps($cmd_file) {
}
fclose($fd);
$total_steps = $loopno*$looprun;
print "total_steps = ".$total_steps;
if($GLOBALS["debug"])print "total_steps = ".$total_steps."<br>";
return $total_steps;
}

function calc_step_cpu($filename) {
$fd = fopen("$filename", "r");
$start_line = "Step CPU ";
$start = 0;
$start_step = 1;
$cur_step = 1;
$avg_cpu = 0;
if (!$fd) {
echo "fail to open file log.1";
exit(-1);
}
$count=0;
while (!feof($fd)) {
$line = fgets($fd,4096);
if (preg_match('/^Step\s+CPU/',$line)) {
//echo $line."\n";
$start = 1;
continue;
}
if (!$start) continue;
$arr = preg_split("/\s+/", $line);
//print_r($arr);

if (count($arr) <=6 || !is_numeric($arr[1])) {
continue;
}
$step = (int)$arr[1];
$cpu = (float)$arr[2];
//echo "step=".$step." cpu=".$cpu."\n";
if ($cpu==0) {
$count=0;
} else {
$count+=1;
if($GLOBALS["debug"])echo "step=".$step." cpu=".$cpu."count=".$count."\n";
if($count >= 10) {
$avg_cpu=$cpu/$count;
if($GLOBALS["debug"])echo "avg_cpu is ".$avg_cpu;
break;
}
}
}
return $avg_cpu;
}

function calc_est_size($lammps_script, $structure_file, $cmd_file){
$dump_types = 0;
$fd = fopen($lammps_script,"r");
Expand All @@ -104,15 +157,15 @@ function calc_est_size($lammps_script, $structure_file, $cmd_file){
}
}
fclose($fd);
print "dump_types= ".$dump_types;
if($GLOBALS["debug"])print "dump_types= ".$dump_types."<br>";

$structure_file_size = filesize($structure_file);
$fd = fopen($cmd_file,"r");
if (!$fd){
echo "can not open file $cmd_file\n";
exit(-1);
}
print "structure_file_size=".$structure_file_size;
if($GLOBALS["debug"]) print "structure_file_size=".$structure_file_size."<br>";

$loopno=1;
while (!feof($fd)){
Expand All @@ -124,50 +177,12 @@ function calc_est_size($lammps_script, $structure_file, $cmd_file){
}
}
fclose($fd);
print "loopno=".$loopno;
if($GLOBALS["debug"])print "loopno=".$loopno."<br>";

$est_size = $loopno*$structure_file_size*0.8*$dump_types;
return $est_size;
}

function calc_step_cpu($filename) {
$fd = fopen("$filename", "r");
$start_line = "Step CPU flow_com avoo";
$start = 0;
$start_step = 1;
$cur_step = 1;
$avg_cpu = 0;
if (!$fd) {
echo "fail to open file log.1";
exit(-1);
}
while (!feof($fd)) {
$line = fgets($fd,4096);
if (strlen($line) > strlen($start_line)
&& substr_compare($line, $start_line, 0, strlen($start_line)) == 0
) {
$start = 1;
continue;
}
if (!$start) continue;
$arr = preg_split("/\s+/", $line);
if (count($arr)!=6 || !is_numeric($arr[1])) {
continue;
}
$step = (int)$arr[1];
$cpu = (float)$arr[2];
if ($cpu==0) {
$start_step = $step;
} else {
$cur_step = $step;
if ($cur_step-$start_step>=9) {
$avg_cpu = $cpu/($cur_step-$start_step);
//echo "avg_cpu is ".$avg_cpu;
break;
}
}
}
return $avg_cpu;
}

function area_select() {
return "
Expand Down Expand Up @@ -283,17 +298,28 @@ function prepare_batch($user) {
symlink($cmdline_file_path, "cmd_variables");
symlink($pot_files_path, "pot_files");
list($error, $est_cpu_time, $disk) = lammps_est();

if($GLOBALS["debug"])print "est_cpu_time is ".$est_cpu_time."<br>";
if ($error==0) {
error_page("LAMMPS test failed");
$err_msgs=file("output");
$err="Your test job <strong>failed</strong><br>Please refer to the following Error Message:<br><p>";
foreach($err_msgs as $line){
$err=$err.$line."<br>";
}
$err=$err." <p>
<a href=sandbox.php><strong> File_Sandbox </strong></a>
<a href=lammps.php><strong> Job_Submit </strong></a>
<a href=submit.php><strong> Job_Control </strong></a>
";
error_page($err);
}


system("rm *");
$info->rsc_fpops_est = $est_cpu_time * 5e9;
$info->rsc_fpops_est = $est_cpu_time * 1.5e9;
$info->rsc_fpops_bound = $info->rsc_fpops_est * 20;

$info->rsc_disk_bound = $disk;

if($disk==0){$info->rsc_disk_bound=1000000;}
else{$info->rsc_disk_bound = $disk;}

$tmpfile = tempnam("/tmp", "lammps_");
file_put_contents($tmpfile, serialize($info));
Expand All @@ -302,15 +328,16 @@ function prepare_batch($user) {
//
$njobs = count(file($cmdline_file_path));
$secs_est = estimated_makespan($njobs, $info->rsc_fpops_est);
$hrs_est = number_format($secs_est/3600, 1);
//assume the server's flops is 1.5G and the average client's flops is 1G
$hrs_est = number_format($secs_est*1.5/60, 2);
$client_mb = number_format($info->rsc_disk_bound/1e6, 1);
$server_mb = number_format($njobs*$info->rsc_disk_bound/1e6, 1);

page_head("Batch prepared");
echo "
Your batch has $njobs jobs.
<p>
Estimated time to completion: $hrs_est hours.
Estimated time to completion: $hrs_est Minutes.
<p>
Estimated client disk usage: $client_mb MB
<p>
Expand All @@ -322,22 +349,24 @@ function prepare_batch($user) {
}

function submit_job($app, $batch_id, $info, $cmdline, $i) {
$cmd = "cd ../..; ./bin/create_work --appname $app->name --batch $batch_id --rsc_fpops_est $info->rsc_fpops_est --rsc_fpops_bound $info->rsc_fpops_bound";
$client_disk=$info->rsc_disk_bound*2;
if($client_disk<50000000) $client_disk=50000000;
$cmd = "cd ../..; ./bin/create_work --appname $app->name --batch $batch_id --rsc_fpops_est $info->rsc_fpops_est --rsc_fpops_bound $info->rsc_fpops_bound --rsc_disk_bound $client_disk";
if ($cmdline) {
$cmd .= " --command_line \"$cmdline\"";
}
$cmd .= " --wu_name batch_".$batch_id."_".$i;
$cmd .= " ".basename($info->structure_file_path);
$cmd .= " ".basename($info->command_file_path);
$cmd .= " ".basename($info->pot_files_path);
//echo "<br> $cmd\n";
echo "<br> $cmd\n";

$ret = system($cmd);
if ($ret === FALSE) {
error_page("can't create job");
} else {
header('Location: submit.php');
}
//if ($ret === FALSE) {
// error_page("can't create job");
// } else {
// header('Location: submit.php');
// }
}

function submit_batch($user, $app) {
Expand Down

0 comments on commit 96b549e

Please sign in to comment.