because main thread works as well.
params.start_resolution = get_int(cscene, "preview_start_resolution");
/* other parameters */
params.start_resolution = get_int(cscene, "preview_start_resolution");
/* other parameters */
- params.threads = b_scene.render().threads();
+ if(b_scene.render().threads_mode() == BL::RenderSettings::threads_mode_FIXED)
+ params.threads = b_scene.render().threads();
+ else
+ params.threads = 0;
params.cancel_timeout = get_float(cscene, "debug_cancel_timeout");
params.reset_timeout = get_float(cscene, "debug_reset_timeout");
params.cancel_timeout = get_float(cscene, "debug_cancel_timeout");
params.reset_timeout = get_float(cscene, "debug_reset_timeout");
-Device *Device::create(DeviceInfo& info, Stats &stats, bool background, int threads)
+Device *Device::create(DeviceInfo& info, Stats &stats, bool background)
{
Device *device;
switch(info.type) {
case DEVICE_CPU:
{
Device *device;
switch(info.type) {
case DEVICE_CPU:
- device = device_cpu_create(info, stats, threads);
+ device = device_cpu_create(info, stats);
break;
#ifdef WITH_CUDA
case DEVICE_CUDA:
break;
#ifdef WITH_CUDA
case DEVICE_CUDA:
virtual int device_number(Device *sub_device) { return 0; }
/* static */
virtual int device_number(Device *sub_device) { return 0; }
/* static */
- static Device *create(DeviceInfo& info, Stats &stats, bool background = true, int threads = 0);
+ static Device *create(DeviceInfo& info, Stats &stats, bool background = true);
static DeviceType type_from_string(const char *name);
static string string_from_type(DeviceType type);
static DeviceType type_from_string(const char *name);
static string string_from_type(DeviceType type);
TaskPool task_pool;
KernelGlobals *kg;
TaskPool task_pool;
KernelGlobals *kg;
- CPUDevice(Stats &stats, int threads_num) : Device(stats)
+ CPUDevice(Stats &stats) : Device(stats)
{
kg = kernel_globals_create();
{
kg = kernel_globals_create();
/* split task into smaller ones, more than number of threads for uneven
* workloads where some parts of the image render slower than others */
list<DeviceTask> tasks;
/* split task into smaller ones, more than number of threads for uneven
* workloads where some parts of the image render slower than others */
list<DeviceTask> tasks;
- task.split(tasks, TaskScheduler::num_threads()+1);
+ task.split(tasks, TaskScheduler::num_threads());
foreach(DeviceTask& task, tasks)
task_pool.push(new CPUDeviceTask(this, task));
foreach(DeviceTask& task, tasks)
task_pool.push(new CPUDeviceTask(this, task));
-Device *device_cpu_create(DeviceInfo& info, Stats &stats, int threads)
+Device *device_cpu_create(DeviceInfo& info, Stats &stats)
- return new CPUDevice(stats, threads);
+ return new CPUDevice(stats);
}
void device_cpu_info(vector<DeviceInfo>& devices)
}
void device_cpu_info(vector<DeviceInfo>& devices)
-Device *device_cpu_create(DeviceInfo& info, Stats &stats, int threads);
+Device *device_cpu_create(DeviceInfo& info, Stats &stats);
Device *device_opencl_create(DeviceInfo& info, Stats &stats, bool background);
Device *device_cuda_create(DeviceInfo& info, Stats &stats, bool background);
Device *device_network_create(DeviceInfo& info, Stats &stats, const char *address);
Device *device_opencl_create(DeviceInfo& info, Stats &stats, bool background);
Device *device_cuda_create(DeviceInfo& info, Stats &stats, bool background);
Device *device_network_create(DeviceInfo& info, Stats &stats, const char *address);
TaskScheduler::init(params.threads);
TaskScheduler::init(params.threads);
- device = Device::create(params.device, stats, params.background, params.threads);
+ device = Device::create(params.device, stats, params.background);
if(params.background) {
buffers = NULL;
if(params.background) {
buffers = NULL;
if(users == 0) {
do_exit = false;
if(users == 0) {
do_exit = false;
- /* launch threads that will be waiting for work */
- if(num_threads == 0)
+ if(num_threads == 0) {
+ /* automatic number of threads will be main thread + num cores */
num_threads = system_cpu_thread_count();
num_threads = system_cpu_thread_count();
+ }
+ else {
+ /* main thread will also work, for fixed threads we count it too */
+ num_threads -= 1;
+ }
+ /* launch threads that will be waiting for work */
threads.resize(num_threads);
thread_level.resize(num_threads);
threads.resize(num_threads);
thread_level.resize(num_threads);
static void init(int num_threads = 0);
static void exit();
static void init(int num_threads = 0);
static void exit();
- static int num_threads() { return threads.size(); }
+ /* number of threads that can work on tasks, main thread counts too */
+ static int num_threads() { return threads.size() + 1; }
+
+ /* test if any session is using the scheduler */
static bool active() { return users != 0; }
protected:
static bool active() { return users != 0; }
protected: