每次执行最大数量的仿真jobs

受限于计算资源; 又不想实时查看job状态,来投递新的jobs;有这时间来局大乱斗不好吗~
1.全局的MAKEFILE 创建finish flag
由于flow中大部分顺序任务的执行依赖于Makefile; 设置全局的make finish flag file的规则,在任何路径,可组合使用make规则,产生完成标志文件;

setenv MAKEFILES "/eda/homes/yang.ming/workspace/Script/Makefile"
# Makefile to create a finish_flag file

# Define the target 'ff'
ff:
        touch run_finish
        @echo "File 'run_finish' created in the current directory."

# Phony target to prevent conflicts with a file named 'ff'
# and to ensure the command is always run when 'make ff' is called.
.PHONY: ff
  1. perl脚本 任务发现 任务投递
    仿真任务数量多,但环境简单一致, 下一步目标是根据参数,自动产生仿真环境,目前是在手动校对环境之后,进行任务投递; 根据顺序执行的flag file是否产生来判断任务是否完成;(可以将make指令优化,查验log,检查运行状态)
#!/usr/bin/perl
use strict;
use warnings;
use Cwd;
use File::Slurp;

# Parse parameters (maximum parallel jobs, replacement parameter 1, replacement parameter 2)
my ($max_jobs, $arg1, $arg2) = (3000, '', '');
($arg1, $arg2, $max_jobs) = @ARGV if @ARGV == 3;
($arg1, $arg2) = @ARGV if @ARGV == 2;
$max_jobs = $ARGV[0] if @ARGV == 1 && $ARGV[0] =~ /^\d+$/;

my $current_dir = getcwd();
print "Base Directory: $current_dir\nMax Jobs: $max_jobs\n";

# Target directory patterns
#my @target_dirs = qw(ICLNetwork* JtagBscanPatterns* ICLNetwork_P1* MemoryBist_P*  ac_par* ac_ser* dc_par*  dc_ser* chain_*);
my @target_dirs = qw(ac_ser*  dc_ser*);

# Collect all task directories
my @pending_tasks;
foreach my $target (@target_dirs) {
    my @found = `find "$current_dir" -type d -name "$target" 2>/dev/null`;
    chomp @found;
    push @pending_tasks, @found;
}

# Main task queue processing
my @active_tasks;
my @tasks;
while (@pending_tasks || @active_tasks) {
    # Start new tasks
    while (@active_tasks < $max_jobs && @pending_tasks) {
        my $dir = shift @pending_tasks;
        prepare_task($dir);
        start_task($dir);
        push @active_tasks, $dir;
        #print "[INFO] Started task: $dir (" . scalar(@active_tasks) . "/$max_jobs running)\n";
        print "[INFO] Started task: \e[32m$dir\e[0m (\e[33m" . scalar(@active_tasks) . "/$max_jobs\e[0m running)\n";
    }
    
    # Wait and check task status
    sleep 300;
    @tasks = @active_tasks;
    @active_tasks = grep { !-e "$_/run_finish" } @active_tasks;
    
    # Clean up completion marker files
    #for my $dir (grep { -e "$_/run_finish" } @active_tasks) {
    #    unlink "$dir/run_finish";
    #}
    for my $dir (grep { -e "$_/run_finish" } @tasks) {
    if (!unlink "$dir/run_finish") {
        warn "Failed to delete $dir/run_finish: $!\n";
    }
}
}

sub prepare_task {
    my ($dir) = @_;
    return unless $arg1 && $arg2;
    
    # Modify symbolic links
    opendir(my $dh, $dir) or return;
    while (my $entry = readdir($dh)) {
        next if $entry =~ /^\.\.?$/;
        my $path = "$dir/$entry";
        next unless -l $path;
        
        my $target = readlink($path);
        if ($target =~ s/\Q$arg1\E/$arg2/g) {
            unlink $path;
            symlink($target, $path) 
                or warn "\e[31mFailed to update symlink: $path -> $target\e[0m\n";
        }
    }
    closedir $dh;
    
    # Modify file contents
    my @files = glob("$dir/*");
    for my $file (@files) {
        next unless -f $file;
        my $content = read_file($file);
        $content =~ s/\Q$arg1\E/$arg2/g;
        write_file($file, $content);
    }
}

sub start_task {
    my ($dir) = @_;
    chdir $dir or return;
    
    my $cmd;
    if (-e "makefile") {
        $cmd = "make clear coms sims ff";
    } elsif (-e "./run_vcs_ac") {
        $cmd = "./run_vcs_ac && touch run_finish";
    } else {
        print "\e[31m[ERROR] No valid command in $dir\e[0m\n";
        return;
    }
    
    my @path = split '/', $dir;
    my $title = join '/', @path[-2..-1];
    system("xfce4-terminal --tab --title='$title' --working-directory='$dir' --command 'csh -c \"$cmd; csh\"' --hold &");
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

旺旺脆兵兵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值