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

spielwiese
Last change on this file since 4f8fd1d was 749d24, checked in by Hans Schoenemann <hannes@…>, 2 years ago
fix: vspace wait
  • Property mode set to 100644
File size: 8.6 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>=vspace::internals::MAX_PROCESS)
213    cpus=vspace::internals::MAX_PROCESS-1;
214  /* start no more than MAX_PROCESS-1 children */
215  int parent_pid=getpid();
216  using namespace vspace;
217  vmem_init();
218  // Create a queue of int
219  VRef<Queue<int> > queue = vnew<Queue<int> >();
220  VRef<Queue<int> > rqueue = vnew<Queue<int> >();
221  for(int i=strat->Ll;i>=0; i--)
222  {
223   queue->enqueue(i); // the tasks: process pair L[i]
224  }
225  for(int i=cpus;i>=0;i--)
226  {
227    queue->enqueue(-1); // stop sign, one for each child
228  }
229  int pid;
230  for (int i=0;i<cpus;i++)
231  {
232    pid = fork_process();
233    if (pid==0) break; //child
234  }
235  if (parent_pid!=getpid()) // child ------------------------------------------
236  {
237    loop
238    {
239      int ind=queue->dequeue();
240      if (ind== -1)
241      {
242        if (TEST_OPT_PROT) printf("child: end of queue\n");
243        rqueue->enqueue(0);
244        exit(0);
245      }
246      int red_result=1;
247      /* picks the element from the lazyset L */
248      LObject P;
249      P = strat->L[ind];
250      if (TEST_OPT_PROT) { printf("."); mflush();}
251      if (pNext(P.p) == strat->tail)
252      {
253        // deletes the short spoly
254        pLmFree(P.p);
255        P.p = NULL;
256        poly m1 = NULL, m2 = NULL;
257        /* spoly */
258        kCheckSpolyCreation(&P, strat, m1, m2);
259        ksCreateSpoly(&P, NULL, strat->use_buckets,
260                    strat->tailRing, m1, m2, strat->R);
261      }
262      if ((P.p == NULL) && (P.t_p == NULL))
263      {
264        red_result = 0;
265      }
266      else
267      {
268        /* reduction */
269        int sl=strat->sl;
270        P.GetP();
271        poly p=redNF(P.p,sl,TRUE,strat);
272        if (p==NULL) red_result=0;
273        #ifdef KDEBUG
274        else
275        {
276          if (TEST_OPT_DEBUG)
277          {
278            printf("p: ");p_wrp(p,currRing, currRing); printf("\n");
279          }
280        }
281        #endif
282      }
283      if (red_result!=0)
284      {
285        if (TEST_OPT_PROT) printf("fail: result: %d\n",red_result);
286        rqueue->enqueue(1);
287        exit(0); // found fail, no need to test further
288      }
289    }
290    exit(0); // all done, quit child
291  }
292  else // parent ---------------------------------------------------
293  {
294    if (TEST_OPT_PROT) printf("%d children created\n",cpus);
295    // wait for all process to stop:
296    // each process sends an 0 at end or a 1 for failure
297    int res;
298    int remaining_children=cpus;
299    while(remaining_children>0)
300    {
301      res=rqueue->dequeue();
302      if (res==0) // a child finished
303      {
304        if (TEST_OPT_PROT) { printf("c");mflush(); }
305        //waitpid(-1,NULL,0); // ? see sig_chld_hdl
306        remaining_children--;
307      }
308      else if (res==1) // not a GB - clean up and return 0
309      {
310        if (TEST_OPT_PROT) { printf("C"); mflush(); }
311        remaining_children--;
312        all_okay=FALSE;
313        // clean queue:
314        int dummy;
315        do
316        {
317          dummy=queue->dequeue(); // remove remaining tasks
318        } while (dummy==0);
319      }
320    }
321    sleep(1); // let all the children finish
322    // removes queues
323    queue.free();
324    rqueue.free();
325    vmem_deinit();
326    return all_okay;
327  }
328#else
329  return kVerify1(F,Q);
330#endif
331}
Note: See TracBrowser for help on using the repository browser.