diff --git a/src/com/sheepit/client/Configuration.java b/src/com/sheepit/client/Configuration.java index 03f691a..e89c25d 100644 --- a/src/com/sheepit/client/Configuration.java +++ b/src/com/sheepit/client/Configuration.java @@ -37,6 +37,7 @@ import com.sheepit.client.os.OS; import lombok.Data; @Data public class Configuration { + public enum ComputeType { CPU_GPU, CPU, GPU } // accept job for ... diff --git a/src/com/sheepit/client/Server.java b/src/com/sheepit/client/Server.java index f82be4d..ac9acc9 100644 --- a/src/com/sheepit/client/Server.java +++ b/src/com/sheepit/client/Server.java @@ -50,6 +50,7 @@ import okhttp3.RequestBody; import okhttp3.Response; import okhttp3.JavaNetCookieJar; +import com.sheepit.client.hardware.cpu.CPU; import com.sheepit.client.Configuration.ComputeType; import com.sheepit.client.Error.ServerCode; import com.sheepit.client.datamodel.CacheFileMD5; @@ -195,7 +196,7 @@ public class Server extends Thread { .add("cpu_family", os.getCPU().family()) .add("cpu_model", os.getCPU().model()) .add("cpu_model_name", os.getCPU().name()) - .add("cpu_cores", String.valueOf(user_config.getNbCores() == -1 ? os.getCPU().cores() : user_config.getNbCores())) + .add("cpu_cores", String.valueOf(user_config.getNbCores() == -1 ? os.getCPU().cores() : Math.max(CPU.MIN_CORES, user_config.getNbCores()))) .add("os", os.name()) .add("os_version", os.getVersion()) .add("ram", String.valueOf(os.getMemory())) @@ -275,7 +276,8 @@ public class Server extends Thread { .addQueryParameter("computemethod", String.valueOf(user_config.computeMethodToInt())) .addQueryParameter("network_dl", String.valueOf(dlStats.getRawAverageSessionSpeed())) .addQueryParameter("network_up", String.valueOf(ulStats.getRawAverageSessionSpeed())) - .addQueryParameter("cpu_cores", String.valueOf(user_config.getNbCores() == -1 ? os.getCPU().cores() : user_config.getNbCores())) + .addQueryParameter("cpu_cores", String.valueOf(user_config.getNbCores() == -1 ? os.getCPU().cores() : + (Math.max(user_config.getNbCores(), CPU.MIN_CORES)))) .addQueryParameter("ram_max", String.valueOf(maxMemory)) .addQueryParameter("rendertime_max", String.valueOf(user_config.getMaxRenderTime())); diff --git a/src/com/sheepit/client/hardware/cpu/CPU.java b/src/com/sheepit/client/hardware/cpu/CPU.java index 371d760..436ead9 100644 --- a/src/com/sheepit/client/hardware/cpu/CPU.java +++ b/src/com/sheepit/client/hardware/cpu/CPU.java @@ -20,7 +20,8 @@ package com.sheepit.client.hardware.cpu; public class CPU { - final public static int MIN_RENDERBUCKET_SIZE = 32; + public static final int MIN_RENDERBUCKET_SIZE = 32; + public static final int MIN_CORES = Runtime.getRuntime().availableProcessors() > 1 ? 2 : 1; private String name; private String model; private String family; diff --git a/src/com/sheepit/client/standalone/Worker.java b/src/com/sheepit/client/standalone/Worker.java index 5925ca7..539d235 100644 --- a/src/com/sheepit/client/standalone/Worker.java +++ b/src/com/sheepit/client/standalone/Worker.java @@ -71,7 +71,7 @@ public class Worker { @Option(name = "-compute-method", usage = "CPU: only use cpu, GPU: only use gpu, CPU_GPU: can use cpu and gpu (not at the same time) if -gpu is not use it will not use the gpu", metaVar = "CPU", required = false) private String method = null; - @Option(name = "-cores", usage = "Number of cores/threads to use for the render", metaVar = "3", required = false) private int nb_cores = -1; + @Option(name = "-cores", usage = "Number of cores/threads to use for the render. The minimum is two cores unless your system only has one", metaVar = "3", required = false) private int nb_cores = -1; @Option(name = "-memory", usage = "Maximum memory allow to be used by renderer, number with unit (800M, 2G, ...)", required = false) private String max_ram = null; diff --git a/src/com/sheepit/client/standalone/swing/activity/Settings.java b/src/com/sheepit/client/standalone/swing/activity/Settings.java index 39aec39..0ca7c67 100644 --- a/src/com/sheepit/client/standalone/swing/activity/Settings.java +++ b/src/com/sheepit/client/standalone/swing/activity/Settings.java @@ -368,7 +368,7 @@ public class Settings implements Activity { display = (double) cpu.cores() / step; } - cpuCores = new JSlider(1, cpu.cores()); + cpuCores = new JSlider(CPU.MIN_CORES, cpu.cores()); cpuCores.setMajorTickSpacing((int) (step)); cpuCores.setMinorTickSpacing(1); cpuCores.setPaintTicks(true); @@ -379,7 +379,7 @@ public class Settings implements Activity { } }); cpuCores.setPaintLabels(true); - cpuCores.setValue(config.getNbCores() != -1 ? config.getNbCores() : cpuCores.getMaximum()); + cpuCores.setValue(config.getNbCores() != -1 ? (Math.max(config.getNbCores(), CPU.MIN_CORES)): cpuCores.getMaximum()); JLabel coreLabel = new JLabel("CPU cores:"); coreLabel.setToolTipText(SwingTooltips.CPU_CORES.getText());