Skip to content

Commit

Permalink
allow cpus=0
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes14 committed Jan 10, 2025
1 parent 5b0f93e commit 1f34541
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 28 deletions.
38 changes: 26 additions & 12 deletions Singular/LIB/assprimeszerodim.lib
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////
version="version assprimeszerodim.lib 4.1.2.0 Feb_2019 "; // $Id$
version="version assprimeszerodim.lib 4.4.0.7 Jan_2025 "; // $Id$
category="Commutative Algebra";
info="
LIBRARY: assprimeszerodim.lib associated primes of a zero-dimensional ideal
Expand Down Expand Up @@ -53,19 +53,26 @@ EXAMPLE: example zeroRadical; shows an example
I = modStd(I, exactness);
}

/* call modular() */
// TODO: write deleteUnluckyPrimes_zeroRadical()
if(exactness)
if(system("cpu")>0)
{
/* call modular() */
// TODO: write deleteUnluckyPrimes_zeroRadical()
if(exactness)
{
ideal F = modular("Assprimeszerodim::zeroRadP", list(I),
Modstd::primeTest_std, Modular::deleteUnluckyPrimes_default,
pTest_zeroRadical, finalTest_zeroRadical);
}
else
{
}
else
{
ideal F = modular("Assprimeszerodim::zeroRadP", list(I),
Modstd::primeTest_std, Modular::deleteUnluckyPrimes_default,
pTest_zeroRadical);
}
}
else
{
ideal F=zeroRadP(I);
}

/* compute the squarefree parts */
Expand Down Expand Up @@ -234,20 +241,27 @@ EXAMPLE: example assPrimes; shows an example
I = J;
kill J;

/* call modular() */
if(exactness)
if (system("cpu")>0)
{
/* call modular() */
if(exactness)
{
ideal F = modular("Assprimeszerodim::modpSpecialAlgDep",
list(I, f, d, a),
Modstd::primeTest_std, Modular::deleteUnluckyPrimes_default,
pTest_assPrimes, finalTest_assPrimes);
}
else
{
}
else
{
ideal F = modular("Assprimeszerodim::modpSpecialAlgDep",
list(I, f, d, a),
Modstd::primeTest_std, Modular::deleteUnluckyPrimes_default,
pTest_assPrimes);
}
}
else
{
ideal F=modpSpecialAlgDep(I,f,d,a);
}

/* compute the components */
Expand Down
2 changes: 1 addition & 1 deletion Singular/LIB/ffmodstd.lib
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ static proc select_the_command(ideal I, list #)
computation first but if this command applied in a machine with a single
core it returns (by default) the command ffmodStdOne
*/
if(getcores() == 1)
if(system("cpu") <= 1)
{
def F = ffmodStdOne(I, #);
return(list("ffmodStdOne", F));
Expand Down
1 change: 1 addition & 0 deletions Singular/LIB/modular.lib
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ static proc finalTest_default(string command, alias list args,

static proc farey_parallel(def farey_arg, bigint farey_N)
{
if(system("cpu")==0) { return(farey(farey_arg,farey_N)); }
arg_type = typeof(farey_arg);
if (arg_type != "bigint" && arg_type != "ideal" && arg_type != "module"
&& arg_type != "matrix" && arg_type != "list")
Expand Down
10 changes: 9 additions & 1 deletion Singular/LIB/resources.lib
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@ PROCEDURES:
/* initialize (lib-)global variables */
static proc mod_init()
{
if(system("cpu")>0)
{
int sem_cores = semaphore(system("--cpus")-1);
exportto(Resources, sem_cores);
int NCORES = system("semaphore", "get_value", sem_cores)+1;
}
else
{
int sem_cores = 0;
int NCORES = 0;
}
exportto(Resources, sem_cores);
exportto(Resources, NCORES);
}

Expand Down
4 changes: 2 additions & 2 deletions Singular/links/ssiLink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1103,8 +1103,8 @@ BOOLEAN ssiOpen(si_link l, short flag, leftv u)
}
loop
{
if (!SI_LINK_OPEN_P(l)) m2_end(0);
if(d->f_read->is_eof) m2_end(0);
if (!SI_LINK_OPEN_P(l)) m2_end(-1);
if(d->f_read->is_eof) m2_end(-1);
leftv h=ssiRead1(l); /*contains an exit.... */
if (feErrors != NULL && *feErrors != '\0')
{
Expand Down
2 changes: 1 addition & 1 deletion Singular/misc_ip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,7 @@ void siInit(char *name)
if (env_cpu!=NULL)
{
int t=atoi(env_cpu);
if ((t>0)&&(t<cpus)) cpus=t;
if ((t>=0)&&(t<cpus)) cpus=t;
}
feSetOptValue(FE_OPT_CPUS, cpus);
// how many threads ? -----------------------------------------------------
Expand Down
13 changes: 8 additions & 5 deletions Singular/tesths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ int main( /* main entry to Singular */
else
errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg);
// not more than MAX_PROCESS cpus
long cpus=(long)feOptValue(FE_OPT_CPUS);
#ifdef HAVE_VSPACE
if (cpus>vspace::internals::MAX_PROCESS) cpus=vspace::internals::MAX_PROCESS;
#endif
feSetOptValue(FE_OPT_CPUS,cpus);

if (errormsg)
{
Expand All @@ -125,6 +120,14 @@ int main( /* main entry to Singular */
default: ;
}
}
long cpus=(long)feOptValue(FE_OPT_CPUS);
#ifdef HAVE_VSPACE
if (cpus>vspace::internals::MAX_PROCESS)
{
cpus=vspace::internals::MAX_PROCESS;
feSetOptValue(FE_OPT_CPUS,cpus);
}
#endif

/* say hello */

Expand Down
4 changes: 0 additions & 4 deletions Tst/Manual/m.lst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ ArnoldAction
arrange
ASCII
ASCII_links
assPrimes
attrib
attrib_1
attrib_2
Expand Down Expand Up @@ -765,7 +764,6 @@ Miscellaneous_oddities_4
mod2id
modDec
ModEqn
modStd
module_containment
module_declarations
module_declarations_BR_PLURAL_BR
Expand Down Expand Up @@ -1142,7 +1140,6 @@ solutionsMod2
solve
solve_IP ; needs solve_IP!
solvelinearpart
Solving_systems_of_polynomial_equations
sort
sortandmap
sortier
Expand Down Expand Up @@ -1182,7 +1179,6 @@ squarefree
squareRoot
sres
Ssi_file_links
Ssi_tcp_links
StabEqn
StabEqnId
standard
Expand Down
2 changes: 0 additions & 2 deletions Tst/Short.lst
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ Short/bug_x_i_j.tst
Short/charseries.tst
Short/charseries_p.tst
Short/classify_s.tst
Short/countedref_s.tst
Short/cyc5_lp.tst
Short/dbm_s.tst
Short/decodegb.tst
Expand Down Expand Up @@ -184,7 +183,6 @@ Short/gaussm_ex.tst
Short/gcd0_s.tst
Short/gcdp_s.tst
Short/gerhard_1_32003_lp.tst
Short/gitfan.tst
Short/graphics.tst
Short/groebner_s.tst
Short/highcorner_s.tst
Expand Down
6 changes: 6 additions & 0 deletions Tst/parallel.lst
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ Long/nfmodsyz_l.tst
Long/primdecint.tst
Long/surfacesignature.tst
Long/symodstd.tst
Manual/assPrimes.tst
Manual/modStd.tst
Manual/Solving_systems_of_polynomial_equations.tst
Manual/Ssi_tcp_links.tst
Manual/timeStd.tst
Manual/waitall.tst
Short/bug_509.tst
Short/assprimeszerodim_s.tst
Short/cornercase_normal.tst
Short/countedref_s.tst
Short/ffmodstd_s.tst
Short/gitfan.tst
Short/waitfirst.tst
Short/waitall.tst
Short/tasks_s.tst
Expand Down

0 comments on commit 1f34541

Please sign in to comment.