source: git/kernel/GBEngine/kverify.cc @ 4c486e

fieker-DuValspielwiese
Last change on this file since 4c486e was 4c486e, checked in by Hans Schoenemann <hannes@…>, 2 years ago
vspace limit: no more than MAX_PROCESS processes Thanks to @collares (https://github.com/Singular/Singular/issues/1117)
  • Property mode set to 100644
File size: 8.5 KB
Line 
1#include "kernel/mod2.h"
2
3#include "misc/mylimits.h"
4#include "misc/options.h"
5#include "kernel/ideals.h"
6#include "kernel/polys.h"
7#include "polys/monomials/ring.h"
8#include "kernel/GBEngine/kutil.h"
9#include "kernel/GBEngine/kverify.h"
10#include "Singular/feOpt.h"
11#include <stdlib.h>
12#include <string.h>
13
14#ifdef HAVE_VSPACE
15#include "kernel/oswrapper/vspace.h"
16#include <sys/types.h>
17#include <sys/wait.h>
18#include <unistd.h>
19#endif
20
21BOOLEAN kVerify1(ideal F, ideal Q)
22/* sequential version */
23{
24  assume (!rIsNCRing(currRing));
25  kStrategy strat=new skStrategy;
26  strat->ak = id_RankFreeModule(F,currRing);
27  strat->kModW=kModW=NULL;
28  strat->kHomW=kHomW=NULL;
29  initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
30  initBuchMoraPos(strat);
31  initBba(strat);
32  initBuchMora(F, Q,strat);
33  /*initBuchMora:*/
34    strat->tail = pInit();
35    /*- set s -*/
36    strat->sl = -1;
37    /*- set L -*/
38    strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
39    strat->Ll = -1;
40    strat->L = initL(strat->Lmax);
41    /*- set B -*/
42    strat->Bmax = setmaxL;
43    strat->Bl = -1;
44    strat->B = initL();
45    /*- set T -*/
46    strat->tl = -1;
47    strat->tmax = setmaxT;
48    strat->T = initT();
49    strat->R = initR();
50    strat->sevT = initsevT();
51    /*- init local data struct.---------------------------------------- -*/
52    strat->P.ecart=0;
53    strat->P.length=0;
54    strat->P.pLength=0;
55    initS(F, Q,strat); /*sets also S, ecartS, fromQ */
56    strat->fromT = FALSE;
57    strat->noTailReduction = FALSE;
58  /*----------------------------------------------------------------------*/
59  /* build pairs */
60  if (strat->fromQ!=NULL)
61  {
62    for(int i=1; i<=strat->sl;i++)
63    {
64      initenterpairs(strat->S[i],i-1,0,strat->fromQ[i],strat);
65    }
66  }
67  else
68  {
69    for(int i=1; i<=strat->sl;i++)
70    {
71      initenterpairs(strat->S[i],i-1,0,FALSE,strat);
72    }
73  }
74  if (TEST_OPT_PROT) printf("%d pairs created\n",strat->Ll+1);
75  if (TEST_OPT_DEBUG) messageSets(strat);
76  /*---------------------------------------------------------------------*/
77  BOOLEAN all_okay=TRUE;
78  for(int i=strat->Ll;i>=0; i--)
79  {
80  /* spolys */
81    int red_result=1;
82    /* picks the last element from the lazyset L */
83    strat->P = strat->L[i];
84    if (pNext(strat->P.p) == strat->tail)
85    {
86      // deletes the short spoly
87      pLmFree(strat->P.p);
88      strat->P.p = NULL;
89      poly m1 = NULL, m2 = NULL;
90      kCheckSpolyCreation(&(strat->P), strat, m1, m2);
91      ksCreateSpoly(&(strat->P), NULL, strat->use_buckets,
92                    strat->tailRing, m1, m2, strat->R);
93    }
94    if ((strat->P.p == NULL) && (strat->P.t_p == NULL))
95    {
96      red_result = 0;
97    }
98    else
99    {
100      if (TEST_OPT_DEGBOUND
101            && (currRing->pFDeg(strat->P.p,currRing)>Kstd1_deg))
102      {
103        /*
104        * omit pair
105        * if 24 IN test and the degree of P is bigger then
106        *a predefined number Kstd1_deg
107        */
108        strat->P.Delete();
109        red_result=0;
110        if (TEST_OPT_PROT) { printf("D"); mflush(); }
111      }
112      else
113      {
114        int sl=strat->sl;
115        strat->P.GetP();
116        poly p=redNF(strat->P.p,sl,TRUE,strat);
117        if (p==NULL) red_result=0;
118        #ifdef KDEBUG
119        else
120        {
121          if (TEST_OPT_DEBUG)
122          {
123            printf("p: ");p_wrp(p,currRing, currRing); printf("\n");
124          }
125        }
126        #endif
127      }
128    }
129    if (red_result!=0)
130    {
131      if (TEST_OPT_PROT) printf("fail: %d, result: %d\n",i,red_result);
132      all_okay=FALSE;
133    }
134  }
135  return all_okay;
136}
137
138BOOLEAN kVerify2(ideal F, ideal Q)
139/* parallel version */
140{
141#ifdef HAVE_VSPACE
142  assume (!rIsNCRing(currRing));
143  kStrategy strat=new skStrategy;
144  strat->ak = id_RankFreeModule(F,currRing);
145  strat->kModW=kModW=NULL;
146  strat->kHomW=kHomW=NULL;
147  initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
148  initBuchMoraPos(strat);
149  initBba(strat);
150  initBuchMora(F, Q,strat);
151  /*initBuchMora:*/
152    strat->tail = pInit();
153    /*- set s -*/
154    strat->sl = -1;
155    /*- set L -*/
156    strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
157    strat->Ll = -1;
158    strat->L = initL(strat->Lmax);
159    /*- set B -*/
160    strat->Bmax = setmaxL;
161    strat->Bl = -1;
162    strat->B = initL();
163    /*- set T -*/
164    strat->tl = -1;
165    strat->tmax = setmaxT;
166    strat->T = initT();
167    strat->R = initR();
168    strat->sevT = initsevT();
169    /*- init local data struct.---------------------------------------- -*/
170    strat->P.ecart=0;
171    strat->P.length=0;
172    strat->P.pLength=0;
173    initS(F, Q,strat); /*sets also S, ecartS, fromQ */
174    strat->fromT = FALSE;
175    strat->noTailReduction = FALSE;
176  /*----------------------------------------------------------------------*/
177  /* build pairs */
178  if (strat->fromQ!=NULL)
179  {
180    for(int i=1; i<=strat->sl;i++)
181    {
182      initenterpairs(strat->S[i],i-1,0,strat->fromQ[i],strat);
183    }
184  }
185  else
186  {
187    for(int i=1; i<=strat->sl;i++)
188    {
189      initenterpairs(strat->S[i],i-1,0,FALSE,strat);
190    }
191  }
192  if (TEST_OPT_PROT) printf("%d pairs created\n",strat->Ll+1);
193  if (TEST_OPT_DEGBOUND)
194  {
195    for(int i=strat->Ll; i>=0; i--)
196    {
197      if (currRing->pFDeg(strat->L[i].p,currRing)>Kstd1_deg)
198      {
199        /*
200        * omit pairs if 24 IN test and the degree of L[i] is bigger then
201        *a predefined number Kstd1_deg
202        */
203        deleteInL(strat->L,&strat->Ll,i,strat);
204        if (TEST_OPT_PROT) { printf("D"); mflush(); }
205      }
206    }
207  }
208  if (TEST_OPT_DEBUG) messageSets(strat);
209  /*---------------------------------------------------------------------*/
210  BOOLEAN all_okay=TRUE;
211  int cpus=(int)(long)feOptValue(FE_OPT_CPUS);
212  if (cpus>=MAX_PROCESS) cpus=MAX_PROCESS-1;
213  /* start no more than MAX_PROCESS-1 children */
214  int parent_pid=getpid();
215  using namespace vspace;
216  vmem_init();
217  // Create a queue of int
218  VRef<Queue<int> > queue = vnew<Queue<int> >();
219  VRef<Queue<int> > rqueue = vnew<Queue<int> >();
220  for(int i=strat->Ll;i>=0; i--)
221  {
222   queue->enqueue(i); // the tasks: process pair L[i]
223  }
224  for(int i=cpus;i>=0;i--)
225  {
226    queue->enqueue(-1); // stop sign, one for each child
227  }
228  int pid;
229  for (int i=0;i<cpus;i++)
230  {
231    pid = fork_process();
232    if (pid==0) break; //child
233  }
234  if (parent_pid!=getpid()) // child ------------------------------------------
235  {
236    loop
237    {
238      int ind=queue->dequeue();
239      if (ind== -1)
240      {
241        if (TEST_OPT_PROT) printf("child: end of queue\n");
242        rqueue->enqueue(0);
243        exit(0);
244      }
245      int red_result=1;
246      /* picks the element from the lazyset L */
247      LObject P;
248      P = strat->L[ind];
249      if (TEST_OPT_PROT) { printf("."); mflush();}
250      if (pNext(P.p) == strat->tail)
251      {
252        // deletes the short spoly
253        pLmFree(P.p);
254        P.p = NULL;
255        poly m1 = NULL, m2 = NULL;
256        /* spoly */
257        kCheckSpolyCreation(&P, strat, m1, m2);
258        ksCreateSpoly(&P, NULL, strat->use_buckets,
259                    strat->tailRing, m1, m2, strat->R);
260      }
261      if ((P.p == NULL) && (P.t_p == NULL))
262      {
263        red_result = 0;
264      }
265      else
266      {
267        /* reduction */
268        int sl=strat->sl;
269        P.GetP();
270        poly p=redNF(P.p,sl,TRUE,strat);
271        if (p==NULL) red_result=0;
272        #ifdef KDEBUG
273        else
274        {
275          if (TEST_OPT_DEBUG)
276          {
277            printf("p: ");p_wrp(p,currRing, currRing); printf("\n");
278          }
279        }
280        #endif
281      }
282      if (red_result!=0)
283      {
284        if (TEST_OPT_PROT) printf("fail: result: %d\n",red_result);
285        rqueue->enqueue(1);
286        exit(0); // found fail, no need to test further
287      }
288    }
289    exit(0); // all done, quit child
290  }
291  else // parent ---------------------------------------------------
292  {
293    if (TEST_OPT_PROT) printf("%d children created\n",cpus);
294    // wait for all process to stop:
295    // each process sends an 0 at end or a 1 for failure
296    int res;
297    int remaining_children=cpus;
298    while(remaining_children>0)
299    {
300      res=rqueue->dequeue();
301      if (res==0) // a child finished
302      {
303        if (TEST_OPT_PROT) { printf("c");mflush(); }
304        //waitpid(-1,NULL,0); // ? see sig_chld_hdl
305        remaining_children--;
306      }
307      else if (res==1) // not a GB - clean up and return 0
308      {
309        if (TEST_OPT_PROT) { printf("C"); mflush(); }
310        remaining_children--;
311        all_okay=FALSE;
312        // clean queue:
313        int dummy;
314        do
315        {
316          dummy=queue->dequeue(); // remove remaining tasks
317        } while (dummy==0);
318      }
319    }
320    // removes queues
321    queue.free();
322    rqueue.free();
323    vmem_deinit();
324    return all_okay;
325  }
326#else
327  return kVerify1(F,Q);
328#endif
329}
Note: See TracBrowser for help on using the repository browser.