Changeset 5c44339 in git


Ignore:
Timestamp:
Mar 30, 2010, 11:45:15 AM (14 years ago)
Author:
Frank Seelisch <seelisch@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
2e1b74af4c420fc8a67df76abb2cc0c8da9990db
Parents:
d0164d9b24d76e7796cf29d9c51710744319272d
Message:
facilities for printing out operation counters for '*' and '+'

git-svn-id: file:///usr/local/Singular/svn/trunk@12691 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
Singular
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • Singular/MinorInterface.cc

    rd0164d9 r5c44339  
    44#include "ideals.h"
    55#include "kstd1.h"
     6#include <MinorInterface.h>
    67#include <MinorProcessor.h>
    7 #include <MinorInterface.h>
    8 
    9 #ifdef COUNT_AND_PRINT_OPERATIONS
    10 int addsPoly  = 0;   /* for the number of additions of two polynomials */
    11 int multsPoly = 0;   /* for the number of multiplications of two polynomials */
    12 int addsMon   = 0;   /* for the number of additions of two monomials */
    13 int multsMon  = 0;   /* for the number of multiplications of two monomials */
    14 void printCounters ()
    15 {
    16   printf("\n");
    17   printf("\n   ~~~> performed %d monomial-monomial-additions,",
    18          addsMon);
    19   printf("\n   ~~~> performed %d monomial-monomial-multiplications",
    20          multsMon);
    21   printf("\n   ~~~> performed %d polynomial-polynomial-additions,",
    22          addsPoly);
    23   printf("\n   ~~~> performed %d polynomial-polynomial-multiplications",
    24          multsPoly);
    25   printf("\n");
    26 }
    27 #endif
    288
    299bool currRingIsOverIntegralDomain ()
     
    173153  bool duplicatesOk = (allDifferent ? false : true);
    174154  int kk = ((k < 0) ? -k : k); /* absolute value of k */
    175 
     155#ifdef COUNT_AND_PRINT_OPERATIONS
     156  printCounters ("starting", true);
     157  int qqq = 0;
     158#endif
    176159  /* looping over all minors: */
    177160  while (mp.hasNextMinor() && ((kk == 0) || (collectedMinors < kk)))
     
    179162    /* retrieving the next minor: */
    180163    theMinor = mp.getNextMinor(algorithm, i);
     164#if (defined COUNT_AND_PRINT_OPERATIONS) && (COUNT_AND_PRINT_OPERATIONS > 1)
     165    qqq++;
     166    printf("after %d", qqq);
     167    printCounters ("-th minor", false);
     168#endif
    181169    f = theMinor.getResult();
    182170    if (idInsertPolyWithTests(iii, collectedMinors, pCopy(f),
     
    184172      collectedMinors++;
    185173  }
     174#ifdef COUNT_AND_PRINT_OPERATIONS
     175  printCounters ("ending", true);
     176#endif
    186177
    187178  /* before we return the result, let's omit zero generators
     
    387378  bool duplicatesOk = (allDifferent ? false : true);
    388379  int kk = ((k < 0) ? -k : k); /* absolute value of k */
    389 
     380#ifdef COUNT_AND_PRINT_OPERATIONS
     381  printCounters ("starting", true);
     382  int qqq = 0;
     383#endif
    390384  /* looping over all minors: */
    391385  while (mp.hasNextMinor() && ((kk == 0) || (collectedMinors < kk)))
     
    393387    /* retrieving the next minor: */
    394388    theMinor = mp.getNextMinor(cch, i);
     389#if (defined COUNT_AND_PRINT_OPERATIONS) && (COUNT_AND_PRINT_OPERATIONS > 1)
     390    qqq++;
     391    printf("after %d", qqq);
     392    printCounters ("-th minor", false);
     393#endif
    395394    f = theMinor.getResult();
    396395    if (idInsertPolyWithTests(iii, collectedMinors, pCopy(f), zeroOk,
     
    398397      collectedMinors++;
    399398  }
     399#ifdef COUNT_AND_PRINT_OPERATIONS
     400  printCounters ("ending", true);
     401#endif
    400402
    401403  /* before we return the result, let's omit zero generators
  • Singular/MinorInterface.h

    rd0164d9 r5c44339  
    11#ifndef MINOR_INTERFACE_H
    22#define MINOR_INTERFACE_H
    3 
    4 /* activate the next define if you want all basic operations
    5    counted and printed when one of the methods documented
    6    herein will be invoked (not fully implemented yet) */
    7 /* #define COUNT_AND_PRINT_OPERATIONS 1 */
    83
    94/* all computations are module char, if char <> 0;
  • Singular/MinorProcessor.cc

    rd0164d9 r5c44339  
    66#include "kstd1.h"
    77#include "kbuckets.h"
     8
     9#ifdef COUNT_AND_PRINT_OPERATIONS
     10long addsPoly        = 0;    /* for the number of additions of two polynomials */
     11long multsPoly       = 0;    /* for the number of multiplications of two polynomials */
     12long addsPolyForDiv  = 0;    /* for the number of additions of two polynomials for
     13                                polynomial division part */
     14long multsPolyForDiv = 0;    /* for the number of multiplications of two polynomials
     15                                for polynomial division part */
     16long multsMon        = 0;    /* for the number of multiplications of two monomials */
     17long multsMonForDiv  = 0;    /* for the number of m-m-multiplications for polynomial
     18                                division part */
     19long savedMultsMFD   = 0;    /* number of m-m-multiplications that could be saved
     20                                when polynomial division would be optimal
     21                                (if p / t1 = t2 + ..., then t1 * t2 = LT(p), i.e.,
     22                                this multiplication need not be performed which
     23                                would save one m-m-multiplication) */
     24long divsMon         = 0;    /* for the number of divisions of two monomials;
     25                                these are all guaranteed to work, i.e., m1/m2 only
     26                                when exponentVector(m1) >= exponentVector(m2) */
     27void printCounters (char* prefix, bool resetToZero)
     28{
     29  printf("%s [p+p(div) | p*p(div) | m*m(div, -save) | m/m ]", prefix);
     30  printf(" = [%ld(%ld) | %ld(%ld) | %ld(%d, -%ld) | %ld]\n",
     31         addsPoly, addsPolyForDiv, multsPoly, multsPolyForDiv,
     32         multsMon, multsMonForDiv, savedMultsMFD, divsMon);
     33  if (resetToZero)
     34  {
     35    multsMon = 0; addsPoly = 0; multsPoly = 0; divsMon = 0;
     36    savedMultsMFD = 0; multsMonForDiv = 0; addsPolyForDiv = 0;
     37    multsPolyForDiv = 0;
     38  }
     39}
     40#endif
     41/* COUNT_AND_PRINT_OPERATIONS */
    842
    943void MinorProcessor::print() const
     
    430464                                                     for accumulated operation
    431465                                                     counters */
     466    bool hadNonZeroEntry = false;
    432467    if (b >= 0)
    433468    {
     
    443478                                            this sub-determinante. */
    444479        {
     480          hadNonZeroEntry = true;
    445481          /* Next MinorKey is mk with row b and column absoluteC omitted: */
    446482          MinorKey subMk = mk.getSubMinorKey(b, absoluteC);
     
    477513                                            this sub-determinante. */
    478514        {
     515          hadNonZeroEntry = true;
    479516          /* Next MinorKey is mk with row absoluteR and column b omitted. */
    480517          MinorKey subMk = mk.getSubMinorKey(absoluteR, b);
     
    494531      }
    495532    }
     533    if (hadNonZeroEntry)
     534    {
    496535      s--; as--; /* first addition was 0 + ..., so we do not count it */
    497       if (s < 0) s = 0; /* may happen when all subminors are zero and no
     536    }
     537    if (s < 0) s = 0; /* may happen when all subminors are zero and no
     538                         addition needs to be performed */
     539    if (as < 0) as = 0; /* may happen when all subminors are zero and no
    498540                           addition needs to be performed */
    499       if (as < 0) as = 0; /* may happen when all subminors are zero and no
    500                              addition needs to be performed */
    501       if (iSB != 0) result = getReduction(result, iSB);
    502       IntMinorValue newMV(result, m, s, am, as, -1, -1);
    503       /* "-1" is to signal that any statistics about the number of retrievals
    504          does not make sense, as we do not use a cache. */
    505       return newMV;
     541    if (iSB != 0) result = getReduction(result, iSB);
     542    IntMinorValue newMV(result, m, s, am, as, -1, -1);
     543    /* "-1" is to signal that any statistics about the number of retrievals
     544       does not make sense, as we do not use a cache. */
     545    return newMV;
    506546  }
    507547}
     
    626666    IntMinorValue mv(0, 0, 0, 0, 0, 0, 0);        /* for storing all
    627667                                                     intermediate minors */
     668    bool hadNonZeroEntry = false;
    628669    if (b >= 0)
    629670    {
     
    641682                                            this sub-determinante. */
    642683        {
     684          hadNonZeroEntry = true;
    643685          /* Next MinorKey is mk with row b and column absoluteC omitted. */
    644686          MinorKey subMk = mk.getSubMinorKey(b, absoluteC);
     
    692734                                            this sub-determinante. */
    693735        {
     736          hadNonZeroEntry = true;
    694737          /* Next MinorKey is mk with row absoluteR and column b omitted. */
    695738          MinorKey subMk = mk.getSubMinorKey(absoluteR, b);
     
    731774                                                 _minorSize, k,
    732775                                                 multipleMinors);
    733     s--; as--; /* first addition was 0 + ..., so we do not count it */
     776    if (hadNonZeroEntry)
     777    {
     778      s--; as--; /* first addition was 0 + ..., so we do not count it */
     779    }
    734780    if (s < 0) s = 0; /* may happen when all subminors are zero and no
    735781                         addition needs to be performed */
     
    911957                                                     ..."a*" for accumulated
    912958                                                     operation counters */
     959    bool hadNonZeroEntry = false;
    913960    if (b >= 0)
    914961    {
     
    925972                                           this sub-determinante. */
    926973        {
     974          hadNonZeroEntry = true;
    927975          /* Next MinorKey is mk with row b and column absoluteC omitted. */
    928976          MinorKey subMk = mk.getSubMinorKey(b, absoluteC);
     
    939987          temp = p_Mult_q(signPoly, temp, currRing);
    940988          result = p_Add_q(result, temp, currRing);
     989#ifdef COUNT_AND_PRINT_OPERATIONS
     990          multsPoly++;
     991          addsPoly++;
     992          multsMon += pLength(mv.getResult()) * pLength(getEntry(b, absoluteC));
     993#endif
    941994          signPoly = NULL;
    942995          s++; m++; as++, am++; /* This is for the addition and multiplication
     
    9621015                                           this sub-determinante. */
    9631016        {
     1017          hadNonZeroEntry = true;
    9641018          /* This is mk with row absoluteR and column b omitted. */
    9651019          MinorKey subMk = mk.getSubMinorKey(absoluteR, b);
     
    9761030          temp = p_Mult_q(signPoly, temp, currRing);
    9771031          result = p_Add_q(result, temp, currRing);
     1032#ifdef COUNT_AND_PRINT_OPERATIONS
     1033          multsPoly++;
     1034          addsPoly++;
     1035          multsMon += pLength(mv.getResult()) * pLength(getEntry(absoluteR, b));
     1036#endif
    9781037          signPoly = NULL;
    9791038          s++; m++; as++, am++; /* This is for the addition and multiplication
     
    9831042      }
    9841043    }
    985     s--; as--; /* first addition was 0 + ..., so we do not count it */
     1044    if (hadNonZeroEntry)
     1045    {
     1046      s--; as--; /* first addition was 0 + ..., so we do not count it */
     1047#ifdef COUNT_AND_PRINT_OPERATIONS
     1048      addsPoly--;
     1049#endif
     1050    }
    9861051    if (s < 0) s = 0; /* may happen when all subminors are zero and no
    9871052                         addition needs to be performed */
     
    10271092                                                     ..."a*" for accumulated
    10281093                                                     operation counters */
     1094    bool hadNonZeroEntry = false;
    10291095    if (b >= 0)
    10301096    {
     
    10421108                                           this sub-determinante. */
    10431109        {
     1110          hadNonZeroEntry = true;
    10441111          PolyMinorValue mv; /* for storing all intermediate minors */
    10451112          /* Next MinorKey is mk with row b and column absoluteC omitted. */
     
    10751142          temp = p_Mult_q(signPoly, temp, currRing);
    10761143          result = p_Add_q(result, temp, currRing);
     1144#ifdef COUNT_AND_PRINT_OPERATIONS
     1145          multsPoly++;
     1146          addsPoly++;
     1147          multsMon += pLength(mv.getResult()) * pLength(getEntry(b, absoluteC));
     1148#endif
    10771149          signPoly = NULL;
    10781150          s++; m++; as++; am++; /* This is for the addition and multiplication
     
    10981170                                           this sub-determinante. */
    10991171        {
     1172          hadNonZeroEntry = true;
    11001173          PolyMinorValue mv; /* for storing all intermediate minors */
    11011174          /* Next MinorKey is mk with row absoluteR and column b omitted. */
     
    11301203          temp = p_Mult_q(signPoly, temp, currRing);
    11311204          result = p_Add_q(result, temp, currRing);
     1205#ifdef COUNT_AND_PRINT_OPERATIONS
     1206          multsPoly++;
     1207          addsPoly++;
     1208          multsMon += pLength(mv.getResult()) * pLength(getEntry(absoluteR, b));
     1209#endif
    11321210          signPoly = NULL;
    11331211          s++; m++; as++; am++; /* This is for the addition and multiplication
     
    11431221                                                 k,
    11441222                                                 multipleMinors);
    1145     s--; as--; /* first addition was 0 + ..., so we do not count it */
     1223    if (hadNonZeroEntry)
     1224    {
     1225      s--; as--; /* first addition was 0 + ..., so we do not count it */
     1226#ifdef COUNT_AND_PRINT_OPERATIONS
     1227      addsPoly--;
     1228#endif
     1229    }
    11461230    if (s < 0) s = 0; /* may happen when all subminors are zero and no
    11471231                         addition needs to be performed */
     
    11811265   p2, p3, and p4 may be pNormalize-d but must, apart from that,
    11821266   not be changed;
    1183    This can only be used in the case of coefficients coming from a field!!! */
     1267   This can only be used in the case of coefficients coming from a field
     1268   or at least an integral domain. */
    11841269void elimOperationBucketNoDiv(poly &p1, poly &p2, poly &p3, poly &p4)
    11851270{
     1271#ifdef COUNT_AND_PRINT_OPERATIONS
     1272  if ((pLength(p1) != 0) && (pLength(p2) != 0))
     1273  {
     1274    multsPoly++;
     1275    multsMon += pLength(p1) * pLength(p2);
     1276  }
     1277  if ((pLength(p3) != 0) && (pLength(p4) != 0))
     1278  {
     1279    multsPoly++;
     1280    multsMon += pLength(p3) * pLength(p4);
     1281  }
     1282  if ((pLength(p1) != 0) && (pLength(p2) != 0) &&
     1283      (pLength(p3) != 0) && (pLength(p4) != 0))
     1284    addsPoly++;
     1285#endif
    11861286  kBucket_pt myBucket = kBucketCreate();
    11871287  addOperationBucket(p1, p2, myBucket);
     
    12001300   c5 is assumed to be the leading coefficient of p5;
    12011301   p5Len is assumed to be the length of p5;
    1202    This can only be used in the case of coefficients coming from a field!!! */
     1302   This can only be used in the case of coefficients coming from a field
     1303   or at least an integral domain. */
    12031304void elimOperationBucket(poly &p1, poly &p2, poly &p3, poly &p4, poly &p5,
    12041305                         number &c5, int p5Len)
    12051306{
     1307#ifdef COUNT_AND_PRINT_OPERATIONS
     1308  if ((pLength(p1) != 0) && (pLength(p2) != 0))
     1309  {
     1310    multsPoly++;
     1311    multsMon += pLength(p1) * pLength(p2);
     1312  }
     1313  if ((pLength(p3) != 0) && (pLength(p4) != 0))
     1314  {
     1315    multsPoly++;
     1316    multsMon += pLength(p3) * pLength(p4);
     1317  }
     1318  if ((pLength(p1) != 0) && (pLength(p2) != 0) &&
     1319      (pLength(p3) != 0) && (pLength(p4) != 0))
     1320    addsPoly++;
     1321#endif
    12061322  kBucket_pt myBucket = kBucketCreate();
    12071323  addOperationBucket(p1, p2, myBucket);
     
    12271343       quotient */
    12281344    p_ExpVectorSub(bucketLm, p5, currRing);
     1345#ifdef COUNT_AND_PRINT_OPERATIONS
     1346    divsMon++;
     1347    multsMonForDiv += p5Len;
     1348    multsMon += p5Len;
     1349    savedMultsMFD++;
     1350    multsPoly++;
     1351    multsPolyForDiv++;
     1352    addsPoly++;
     1353    addsPolyForDiv++;
     1354#endif
    12291355    kBucket_Minus_m_Mult_p(myBucket, bucketLm, p5, &p5Len);
    12301356    /* The following lines make bucketLm the new leading term of p1,
     
    13241450        sign = -sign;
    13251451      }
     1452#if (defined COUNT_AND_PRINT_OPERATIONS) && (COUNT_AND_PRINT_OPERATIONS > 2)
     1453      poly w = NULL; int wl = 0;
     1454      printf("matrix after %d steps:\n", r);
     1455      for (int u = 0; u < k; u++)
     1456      {
     1457        for (int v = 0; v < k; v++)
     1458        {
     1459          if ((v < r) && (u > v))
     1460            wl = 0;
     1461          else
     1462          {
     1463            w = tempMatrix[rowPermutation[u] * k + v];
     1464            wl = pLength(w);
     1465          }
     1466          printf("%5d  ", wl);
     1467        }
     1468        printf("\n");
     1469      }
     1470      printCounters ("", false);
     1471#endif
    13261472      if (r != 0)
    13271473      {
     
    13471493        }
    13481494    }
     1495#if (defined COUNT_AND_PRINT_OPERATIONS) && (COUNT_AND_PRINT_OPERATIONS > 2)
     1496    poly w = NULL; int wl = 0;
     1497    printf("matrix after %d steps:\n", k - 1);
     1498    for (int u = 0; u < k; u++)
     1499    {
     1500      for (int v = 0; v < k; v++)
     1501      {
     1502        if ((v < k - 1) && (u > v))
     1503          wl = 0;
     1504        else
     1505        {
     1506          w = tempMatrix[rowPermutation[u] * k + v];
     1507          wl = pLength(w);
     1508        }
     1509        printf("%5d  ", wl);
     1510      }
     1511      printf("\n");
     1512    }
     1513#endif
    13491514    poly result = tempMatrix[rowPermutation[k - 1] * k + k - 1];
    13501515    if (sign == -1) result = pNeg(result);
  • Singular/MinorProcessor.h

    rd0164d9 r5c44339  
    66#include <assert.h>
    77#include <string>
     8
     9/* write "##define COUNT_AND_PRINT_OPERATIONS x" if you want
     10   to count all basic operations and have them printed when
     11   one of the methods documented herein will be invoked;
     12   otherwise, comment this line;
     13   x = 1: only final counters (after computing ALL
     14          specified minors) will be printed, i.e., no
     15          intermediate results;
     16   x = 2: print counters after the computation of each
     17          minor; this will be much more information
     18   x = 3: print also all intermediate matrices with the
     19          numbers of monomials in each entry;
     20          this will be much much more information */
     21#define COUNT_AND_PRINT_OPERATIONS 2
     22
     23void printCounters (char* prefix, bool resetToZero);
    824
    925/*! \class MinorProcessor
Note: See TracChangeset for help on using the changeset viewer.