Fix: -compute-method not set when configuration file present (#268)

This commit is contained in:
Luis Uguina
2020-06-21 02:31:31 +10:00
committed by GitHub
parent 7685051662
commit 608e1d7aea
2 changed files with 26 additions and 21 deletions

View File

@@ -361,9 +361,15 @@ public class SettingsLoader {
config.setUsePriority(priority); config.setUsePriority(priority);
} }
try { try {
if ((config.getComputeMethod() == null && computeMethod != null) || (computeMethod != null && config.getComputeMethod() != ComputeType if (config.getComputeMethod() == null && computeMethod == null) {
config.setComputeMethod(ComputeType.CPU);
}
else if ((config.getComputeMethod() == null && computeMethod != null) || (computeMethod != null && config.getComputeMethod() != ComputeType
.valueOf(computeMethod))) { .valueOf(computeMethod))) {
config.setComputeMethod(ComputeType.valueOf(computeMethod)); if (config.getComputeMethod() == null) {
config.setComputeMethod(ComputeType.valueOf(computeMethod));
}
} }
} }
catch (IllegalArgumentException e) { catch (IllegalArgumentException e) {

View File

@@ -112,7 +112,7 @@ public class Worker {
return; return;
} }
ComputeType compute_method = ComputeType.CPU; ComputeType compute_method = null;
Configuration config = new Configuration(null, login, password); Configuration config = new Configuration(null, login, password);
config.setPrintLog(print_log); config.setPrintLog(print_log);
config.setUsePriority(priority); config.setUsePriority(priority);
@@ -223,10 +223,7 @@ public class Worker {
} }
} }
else { else {
if (config.getGPUDevice() == null) { if (config.getGPUDevice() != null) {
compute_method = ComputeType.CPU;
}
else {
compute_method = ComputeType.GPU; compute_method = ComputeType.GPU;
} }
} }
@@ -246,22 +243,24 @@ public class Worker {
config.setExtras(extras); config.setExtras(extras);
} }
if (compute_method == ComputeType.CPU && config.getGPUDevice() != null) { if (compute_method != null) {
System.err.println( if (compute_method == ComputeType.CPU && config.getGPUDevice() != null) {
System.err.println(
"ERROR: The compute method is set to use CPU only, but a GPU has also been specified. Change the compute method to CPU_GPU or remove the GPU"); "ERROR: The compute method is set to use CPU only, but a GPU has also been specified. Change the compute method to CPU_GPU or remove the GPU");
System.exit(2); System.exit(2);
} }
else if (compute_method == ComputeType.CPU_GPU && config.getGPUDevice() == null) { else if (compute_method == ComputeType.CPU_GPU && config.getGPUDevice() == null) {
System.err.println( System.err.println(
"ERROR: The compute method is set to use both CPU and GPU, but no GPU has been specified. Change the compute method to CPU or add a GPU (via -gpu parameter)"); "ERROR: The compute method is set to use both CPU and GPU, but no GPU has been specified. Change the compute method to CPU or add a GPU (via -gpu parameter)");
System.exit(2); System.exit(2);
} }
else if (compute_method == ComputeType.GPU && config.getGPUDevice() == null) { else if (compute_method == ComputeType.GPU && config.getGPUDevice() == null) {
System.err.println("ERROR: The compute method is set to use GPU only, but not GPU has been specified. Please add a GPU (via -gpu parameter)"); System.err.println("ERROR: The compute method is set to use GPU only, but not GPU has been specified. Please add a GPU (via -gpu parameter)");
System.exit(2); System.exit(2);
} }
else if (compute_method == ComputeType.CPU) { else if (compute_method == ComputeType.CPU) {
config.setGPUDevice(null); // remove the GPU config.setGPUDevice(null); // remove the GPU
}
} }
config.setComputeMethod(compute_method); config.setComputeMethod(compute_method);