Check-in [cc3e0b7bd2]
Overview
Comment:Run the same number of concurrent jobs as CPUs
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: cc3e0b7bd252d76be8f9666653f4263a3e442268393872d8cb4bb3c52b76f53a
User & Date: rkeene on 2018-08-17 19:13:44.472
Other Links: manifest | tags
Context
2018-08-17
20:37
Start of work on OpenMP GPU offloading for work generation check-in: f87706a75e user: rkeene tags: trunk
19:13
Run the same number of concurrent jobs as CPUs check-in: cc3e0b7bd2 user: rkeene tags: trunk
16:21
Added script which can be used to generate blocks for a stress test check-in: 94a2cee313 user: rkeene tags: trunk
Changes
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33






























34

35

36
37
38
39
40
41
42
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

65
66
67
68
69
70
71
72







-








+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
-
+







		db eval {INSERT INTO blocks (orderID, blockJSON) VALUES ($orderID, $block);}
	}
}

set ::initDB true
uplevel #0 $threadInit

set ::numberOfCPUs 2
set iterationCount 1

db eval {
	PRAGMA journal_mode = MEMORY;
	CREATE TABLE blocks (orderID INTEGER PRIMARY KEY, blockJSON TEXT NOT NULL);
}

## -- PROCESSES
proc numberOfThreads {} {
	# Windows puts it in an environment variable
	if {[info exists ::env(NUMBER_OF_PROCESSORS)]} {
		return $::env(NUMBER_OF_PROCESSORS)
	    }

	# Check for sysctl (OSX, BSD)
	set sysctl [auto_execok "sysctl"]
	if {[llength $sysctl]} {
		if {![catch {exec {*}$sysctl -n "hw.ncpu"} cores]} {
			if {[string is integer -strict $cores]} {
				return $cores
			}
		}
	}

	# Assume Linux, which has /proc/cpuinfo, but be careful
	if {![catch {open "/proc/cpuinfo"} f]} {
		set cores [regexp -all -line {^processor\s} [read $f]]
		close $f
		if {$cores > 0} {
			return $cores
		}
	}

	# No idea what the actual number of cores is; exhausted all our options
	# Fall back to returning 1; there must be at least that because we're running on it!
	return 1
}

set ::jobIDs [list]
set ::numberOfThreads [numberOfThreads]
set ::threadPool [::tpool::create -minworkers $::numberOfCPUs -maxworkers $::numberOfCPUs -initcmd $::threadInit]
set ::threadPool [::tpool::create -minworkers $numberOfThreads -maxworkers $numberOfThreads -initcmd $::threadInit]
set ::processBlock_orderID -1
proc processBlock {args} {
	updateStatus

	incr ::processBlock_orderID
	
	set jobID [::tpool::post $::threadPool [list processBlockWorker ${::processBlock_orderID} {*}$args]]