Skip to content

Commit

Permalink
Merge branch 'jobQueue2' of github.com:haydenc-amd/RapidWright into c…
Browse files Browse the repository at this point in the history
…reatePhysNetsFromLogical
  • Loading branch information
haydenc-amd committed Aug 17, 2023
2 parents 2579a81 + 2d14f3b commit 908ad82
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 25 deletions.
25 changes: 21 additions & 4 deletions src/com/xilinx/rapidwright/util/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public abstract class Job {

public static final String DEFAULT_COMMAND_LOG_FILE = DEFAULT_COMMAND_NAME + DEFAULT_LOG_EXTENSION;

private String scriptBaseName=DEFAULT_SCRIPT_NAME;
private String scriptLogFile = DEFAULT_SCRIPT_LOG_FILE;
private String cmdLogFile = DEFAULT_COMMAND_LOG_FILE;


public abstract long launchJob();

public abstract JobState getJobState();
Expand All @@ -78,14 +83,26 @@ public Pair<String,String> createLaunchScript() {
FileTools.makeDirs(dir);

startupScript.add("cd " + dir);
startupScript.add(getCommand() + " > " + DEFAULT_COMMAND_LOG_FILE + " 2>&1");
startupScript.add(getCommand() + " > " + cmdLogFile + " 2>&1");

String startupScriptName = dir + File.separator + DEFAULT_SCRIPT_NAME + scriptExt;
String startupScriptName = dir + File.separator + scriptBaseName + scriptExt;
FileTools.writeLinesToTextFile(startupScript, startupScriptName);
new File(startupScriptName).setExecutable(true);
String startupScriptLog = dir + File.separator + DEFAULT_SCRIPT_LOG_FILE;
String startupScriptLog = dir + File.separator + scriptLogFile;
return new Pair<String,String>(startupScriptName,startupScriptLog);
}

/**
* @param scriptBaseName the script's base name to set
*/
public void setScriptBaseName(String scriptBaseName) {this.scriptBaseName = scriptBaseName;}


/**
* @return the path to the command logfile
*/
public String getCommandLogFileName(){return cmdLogFile;}

/**
* @return the command
*/
Expand Down Expand Up @@ -157,6 +174,6 @@ public Optional<List<String>> getLastLogLines() {
}

public String getLogFilename() {
return getRunDir() + File.separator + Job.DEFAULT_COMMAND_LOG_FILE;
return getRunDir() + File.separator + this.cmdLogFile;
}
}
61 changes: 40 additions & 21 deletions src/com/xilinx/rapidwright/util/JobQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,33 +80,52 @@ public boolean addRunningJob(Job j) {
return running.add(j);
}

public int getRunningCount() {
return running.size();
}

private Map<JobState, List<Job>> getJobsByState() {
return running.stream().collect(Collectors.groupingBy(Job::getJobState, () -> new EnumMap<>(JobState.class), Collectors.toList()));
}

public boolean refreshQueue() {
return refreshQueue(isLSFAvailable() ? JobQueue.MAX_LSF_CONCURRENT_JOBS : JobQueue.MAX_LOCAL_CONCURRENT_JOBS);
}
public boolean refreshQueue(int maxNumRunningJobs) {
return refreshQueue(maxNumRunningJobs, getJobsByState());
}

private boolean refreshQueue(int maxNumRunningJobs, final Map<JobState, List<Job>> jobsByState) {
final List<Job> exited = jobsByState.get(JobState.EXITED);
if (exited != null) {
for (Job job : exited) {
running.remove(job);
finished.add(job);
}
//Removing from map so they don't show up in our printout
jobsByState.remove(JobState.EXITED);
}
boolean launched = false;
while (!waitingToRun.isEmpty() && maxNumRunningJobs > running.size()) {
Job j = waitingToRun.poll();
long pid = j.launchJob();
running.add(j);
if (printJobStart) {
System.out.println("Running job [" + pid + "] " + j.getCommand() + " in " + j.getRunDir());
}
launched = true;
}
return launched;
}

public boolean runAllToCompletion() {
return runAllToCompletion(isLSFAvailable() ? JobQueue.MAX_LSF_CONCURRENT_JOBS : JobQueue.MAX_LOCAL_CONCURRENT_JOBS);
}

public boolean runAllToCompletion(int maxNumRunningJobs) {
while (!waitingToRun.isEmpty() || !running.isEmpty()) {

final Map<JobState, List<Job>> jobsByState = running.stream().collect(Collectors.groupingBy(Job::getJobState, ()->new EnumMap<>(JobState.class), Collectors.toList()));
final List<Job> exited = jobsByState.get(JobState.EXITED);
if (exited != null) {
for (Job job : exited) {
running.remove(job);
finished.add(job);
}
//Removing from map so they don't show up in our printout
jobsByState.remove(JobState.EXITED);
}
boolean launched = false;
while (!waitingToRun.isEmpty() && maxNumRunningJobs > running.size()) {
Job j = waitingToRun.poll();
long pid = j.launchJob();
running.add(j);
if (printJobStart) {
System.out.println("Running job [" + pid + "] " + j.getCommand() + " in " + j.getRunDir());
}
launched = true;
}
final Map<JobState, List<Job>> jobsByState = getJobsByState();
boolean launched = refreshQueue(maxNumRunningJobs, getJobsByState());

if (!launched || !printJobStart) {
System.out.print("Waiting on ");
Expand Down

0 comments on commit 908ad82

Please sign in to comment.