From 608e1d7aeaf546c1718e4ead48ab2e9287a371f1 Mon Sep 17 00:00:00 2001 From: Luis Uguina Date: Sun, 21 Jun 2020 02:31:31 +1000 Subject: [PATCH] Fix: -compute-method not set when configuration file present (#268) --- src/com/sheepit/client/SettingsLoader.java | 10 ++++- src/com/sheepit/client/standalone/Worker.java | 37 +++++++++---------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/com/sheepit/client/SettingsLoader.java b/src/com/sheepit/client/SettingsLoader.java index 445462b..4e6dc7b 100644 --- a/src/com/sheepit/client/SettingsLoader.java +++ b/src/com/sheepit/client/SettingsLoader.java @@ -361,9 +361,15 @@ public class SettingsLoader { config.setUsePriority(priority); } 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))) { - config.setComputeMethod(ComputeType.valueOf(computeMethod)); + if (config.getComputeMethod() == null) { + config.setComputeMethod(ComputeType.valueOf(computeMethod)); + } + } } catch (IllegalArgumentException e) { diff --git a/src/com/sheepit/client/standalone/Worker.java b/src/com/sheepit/client/standalone/Worker.java index 63a773e..1ae0b95 100644 --- a/src/com/sheepit/client/standalone/Worker.java +++ b/src/com/sheepit/client/standalone/Worker.java @@ -112,7 +112,7 @@ public class Worker { return; } - ComputeType compute_method = ComputeType.CPU; + ComputeType compute_method = null; Configuration config = new Configuration(null, login, password); config.setPrintLog(print_log); config.setUsePriority(priority); @@ -223,10 +223,7 @@ public class Worker { } } else { - if (config.getGPUDevice() == null) { - compute_method = ComputeType.CPU; - } - else { + if (config.getGPUDevice() != null) { compute_method = ComputeType.GPU; } } @@ -246,22 +243,24 @@ public class Worker { config.setExtras(extras); } - if (compute_method == ComputeType.CPU && config.getGPUDevice() != null) { - System.err.println( + if (compute_method != null) { + 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"); - System.exit(2); - } - else if (compute_method == ComputeType.CPU_GPU && config.getGPUDevice() == null) { - System.err.println( + System.exit(2); + } + else if (compute_method == ComputeType.CPU_GPU && config.getGPUDevice() == null) { + 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)"); - System.exit(2); - } - 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.exit(2); - } - else if (compute_method == ComputeType.CPU) { - config.setGPUDevice(null); // remove the GPU + System.exit(2); + } + 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.exit(2); + } + else if (compute_method == ComputeType.CPU) { + config.setGPUDevice(null); // remove the GPU + } } config.setComputeMethod(compute_method);