IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41154 for trunk


Ignore:
Timestamp:
Nov 27, 2019, 5:29:35 AM (7 years ago)
Author:
eugene
Message:

added 2 new swap functions; added memory dump options

Location:
trunk/Ohana/src/libohana
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libohana/include/ohana_allocate.h

    r39457 r41154  
    4444void ohana_memcheck_block_func (const char *myFile, int myLine, const char *myFunc, void *in);
    4545void  real_free (void *in);
     46
     47void ohana_memdump_strings_file (FILE *f, int VERBOSE);
     48void ohana_memdump_set_maxlines (int N);
    4649
    4750# define ohana_memcheck(X) ohana_memcheck_func (__FILE__, __LINE__, __func__, X)
  • trunk/Ohana/src/libohana/include/ohana_sort.h

    r40291 r41154  
    8383void isortfour (int *X, int *Y, int *Z, int *W, int N);
    8484
     85void dsort_indexonly (double *X, off_t *S, off_t N);
     86void dsort_int_indexonly (double *X, int *S, int N);
     87
    8588#endif
  • trunk/Ohana/src/libohana/src/ohana_allocate.c

    r40117 r41154  
    4545
    4646static pthread_mutex_t memBlockListMutex = PTHREAD_MUTEX_INITIALIZER;
     47
     48static int NblockMaxDump = 100;
    4749
    4850void ohana_meminit () {
     
    435437        fprintf (stderr, "memory corruption\n");
    436438      }
    437       if (Nbad < 100) {
     439      if (Nbad < NblockMaxDump) {
    438440        fprintf (stderr, "  file: %s, line: %d, func: %s\n", thisBlock->file, thisBlock->line, thisBlock->func);
    439441      }
     
    613615    Nbytes += thisBlock->size;
    614616
    615     if (Ntotal < 100) {
     617    if (Ntotal < NblockMaxDump) {
    616618      if (good) {
    617619        fprintf (f, "  %zd  %zd  %zd  GOOD  %s %d, func: %s\n", Ntotal, thisBlock->size, Nbytes, thisBlock->file, thisBlock->line, thisBlock->func);
     
    677679  return memstats;
    678680}
     681
     682void ohana_memdump_strings_file (FILE *f, int VERBOSE) {
     683
     684  if (!lastBlock) {
     685    if (VERBOSE) fprintf (f, "no memory allocated\n");
     686    return;
     687  }
     688
     689  OhanaMemblock *thisBlock = lastBlock;
     690
     691  size_t Ntotal = 0;
     692  size_t Nbytes = 0;
     693  size_t Nstring = 0;
     694
     695  fprintf (f, "    entry |    bytes | cumulative : line : string\n");
     696
     697  while (thisBlock) {
     698
     699    // pointer to the start of the user memory
     700    char *ptr = (char *)(thisBlock + 1);
     701
     702    Ntotal ++;
     703    Nbytes += thisBlock->size;
     704
     705    int N = strlen(thisBlock->file);
     706    if (N > 22) {
     707      int found = !strcmp("libohana/src/string.c", &thisBlock->file[N - 21]);
     708      if (found) {
     709        if (Nstring < NblockMaxDump) {
     710          fprintf (f, " %8zd | %8zd | %10zd : %4d : %s\n", Ntotal, thisBlock->size, Nbytes, thisBlock->line, ptr);
     711        }
     712        Nstring ++;
     713      }
     714      thisBlock = thisBlock->prevBlock;
     715    }
     716  }
     717
     718  if (Nstring || VERBOSE) {
     719    fprintf (f, "%zd strings allocated\n", Nstring);
     720  }
     721
     722  return;
     723}
     724
     725void ohana_memdump_set_maxlines (int N) {
     726  NblockMaxDump = N;
     727}
  • trunk/Ohana/src/libohana/src/sorts.c

    r40291 r41154  
    196196}
    197197
     198/* sort the index of a vector (vector stays unsorted) */
     199void dsort_indexonly (double *X, off_t *S, off_t N) {
     200 
     201# define SWAPFUNC(A,B){ off_t itmp; \
     202  itmp = S[A]; S[A] = S[B]; S[B] = itmp; \
     203}
     204# define COMPARE(A,B)((!isfinite(X[S[A]]) && isfinite(X[S[B]])) || (X[S[A]] < X[S[B]]))
     205
     206  OHANA_SORT (N, COMPARE, SWAPFUNC);
     207
     208# undef SWAPFUNC
     209# undef COMPARE
     210
     211}
     212
     213/* sort the index of a vector (vector stays unsorted) */
     214void dsort_int_indexonly (double *X, int *S, int N) {
     215 
     216# define SWAPFUNC(A,B){ int itmp; \
     217  itmp = S[A]; S[A] = S[B]; S[B] = itmp; \
     218}
     219# define COMPARE(A,B)((!isfinite(X[S[A]]) && isfinite(X[S[B]])) || (X[S[A]] < X[S[B]]))
     220
     221  OHANA_SORT (N, COMPARE, SWAPFUNC);
     222
     223# undef SWAPFUNC
     224# undef COMPARE
     225
     226}
     227
     228
Note: See TracChangeset for help on using the changeset viewer.