MCPcopy Create free account
hub / github.com/Singular/Singular / createThreadPoolSet

Function createThreadPoolSet

Singular/dyn_modules/systhreads/shared.cc:2161–2211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2159}
2160
2161static BOOLEAN createThreadPoolSet(leftv result, leftv arg) {
2162 Command cmd("createThreadPoolSet", result, arg);
2163 cmd.check_argc(2);
2164 cmd.check_arg(0, INT_CMD, "first argument must be an integer");
2165 cmd.check_arg(1, LIST_CMD, "second argument must be a list of integers");
2166 lists l;
2167 int n;
2168 if (cmd.ok()) {
2169 l = (lists) (cmd.arg(1));
2170 n = lSize(l)+1;
2171 if (n == 0)
2172 return cmd.abort("second argument must not be empty");
2173 for (int i = 0; i < n; i++) {
2174 if (l->m[i].Typ() != INT_CMD)
2175 return cmd.abort("second argument must be a list of integers");
2176 }
2177 }
2178 lists pools = (lists) omAlloc0Bin(slists_bin);
2179 pools->Init(n);
2180 if (cmd.ok()) {
2181 long s = 0;
2182 for (int i = 0; i < n; i++) {
2183 s += (long) (l->m[i].Data());
2184 }
2185 Scheduler *sched = new Scheduler((int)s);
2186 sched->set_maxconcurrency(cmd.int_arg(0));
2187 for (int i = 0; i < n; i++) {
2188 long m = (long) (l->m[i].Data());
2189 ThreadPool *pool = new ThreadPool(sched, (int) m);
2190 pool->set_type(type_threadpool);
2191 for (int j = 0; j < m; j++) {
2192 const char *error;
2193 SchedInfo *info = new SchedInfo();
2194 info->scheduler = pool->scheduler;
2195 acquireShared(pool->scheduler);
2196 info->job = NULL;
2197 info->num = i;
2198 ThreadState *thread = newThread(Scheduler::main, info, &error);
2199 if (!thread) {
2200 // TODO: clean up bad pool
2201 return cmd.abort(error);
2202 }
2203 pool->addThread(thread);
2204 }
2205 pools->m[i].rtyp = type_threadpool;
2206 pools->m[i].data = new_shared(pool);
2207 }
2208 cmd.set_result(LIST_CMD, pools);
2209 }
2210 return cmd.status();
2211}
2212
2213ThreadPool *createThreadPool(int nthreads, int prioThreads = 0) {
2214 ThreadPool *pool = new ThreadPool((int) nthreads);

Callers

nothing calls this directly

Calls 15

lSizeFunction · 0.85
omAlloc0BinFunction · 0.85
acquireSharedFunction · 0.85
newThreadFunction · 0.85
new_sharedFunction · 0.85
check_argcMethod · 0.80
check_argMethod · 0.80
argMethod · 0.80
set_maxconcurrencyMethod · 0.80
int_argMethod · 0.80
set_typeMethod · 0.80
set_resultMethod · 0.80

Tested by

no test coverage detected