BarryFSmith avatar BarryFSmith committed 51c90db

remove use of TASK_INFO on apple for memory size (broken for a long time) and fix rusage case for Apple

Comments (0)

Files changed (2)

config/PETSc/utilities/getResidentSetSize.py

     self.functions.functions.append('getrusage')
     self.functions.functions.append('sbreak')
     self.functions.functions.append('getpagesize')
-    self.functions.functions.append('task_info')
     return
 
   def configureMemorySize(self):
         except:
           pass
 
-    # task_info() is  used on Mach and darwin (MacOS X) systems
-    if self.functions.haveFunction('task_info') and not self.framework.argDB['with-batch']:
-      (output,status) = self.outputRun('#include <mach/mach.h>\n#include <stdlib.h>\n#include <stdio.h>\n','''#define  ARRAYSIZE 10000000
-          int *m,i;
-          unsigned int count;
-          task_basic_info_data_t ti1,ti2;
-          double ratio;
-
-          if (task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&ti1,&count) != KERN_SUCCESS) {
-            printf("failed calling task_info()");
-            return 1;
-          }
-          printf("original resident size %g \\n",(double)ti1.resident_size);
-          m = malloc(ARRAYSIZE*sizeof(int));
-          if (!m) {
-            printf("Error calling malloc()\\n");
-            return 2;
-          }
-          for (i=0; i<ARRAYSIZE; i++){
-            m[i] = i+1;
-          }
-          if (task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&ti2,&count) != KERN_SUCCESS) {
-            printf("failed calling task_info()");
-            return 3;
-          }
-          printf("final resident size %g \\n",(double)ti2.resident_size);
-          ratio = ((double)ti2.resident_size - ti1.resident_size)/(ARRAYSIZE*sizeof(int));
-          printf("Should be near 1.0 %g \\n",ratio);
-          if (ratio > .95 && ratio < 1.05) {
-            printf("task_info() returned a reasonable resident size\\n");
-            return 0;
-          }
-          return 4;''')
-      if status == 0:
-        self.framework.logPrint("Using task_info() for PetscMemoryGetCurrentUsage()")
-        return
-      self.delDefine('HAVE_TASK_INFO')
-      self.framework.logPrint("task_info() does not work\n"+output)
-
     # getrusage() is still used on BSD systems
     if self.functions.haveFunction('getrusage') and not self.framework.argDB['with-batch']:
       if self.functions.haveFunction('getpagesize'):
             #include <sys/stat.h>\n#include <sys/resource.h>\n#include <stdlib.h>''','''#define ARRAYSIZE 10000000
             int i,*m;
             struct   rusage temp1,temp2;
-            double f1,f2;
+            double f0,f1,f2;
 
             if (getrusage(RUSAGE_SELF,&temp1)) {
               printf("Error calling getrusage()\\n");
               return -1;
             }
 
+            f0 = ((double)(temp2.ru_maxrss-temp1.ru_maxrss))/(4.0*ARRAYSIZE);
             f1 = 1024.0 * ((double)(temp2.ru_maxrss-temp1.ru_maxrss))/(4.0*ARRAYSIZE);
             f2 = getpagesize() * ((double)(temp2.ru_maxrss-temp1.ru_maxrss))/(4.0*ARRAYSIZE);
-            printf("Final value %g Initial value %g 1K Scaled Increment %g pagesize scaled Increment %g\\n",(double)(temp2.ru_maxrss),(double)(temp1.ru_maxrss),f1,f2);
+            printf("Final value %g Initial value %g Increment %g 1K Scaled Increment %g pagesize scaled Increment %g\\n",(double)(temp2.ru_maxrss),(double)(temp1.ru_maxrss),f0,f1,f2);
 
             if (f1 == 0) {
               printf("getrusage() does not work\\n");
               return 0;
             }
+            if (f0 > .90 && f0 < 1.1) {
+              printf("uses bytes in getrusage()\\n");
+              return 1;
             if (f1 > .90 && f1 < 1.1) {
               printf("uses 1024 size chunks in getrusage()\\n");
-              return 1;
+              return 2;
             } else if (f2 > .9 && f2 < 1.1) {
               printf("uses getpagesize() chunks in getrusage()\\n");
-              return 2;
+              return 3;
             }
-            printf("unable to determine if uses 1024 or getpagesize() chunks in getrusage()\\n");
+            printf("unable to determine if uses bytes, 1024 or getpagesize() chunks in getrusage()\\n");
             return -2;''')
         if status > 0:
           if status == 1:
+            self.addDefine('USE_BYTES_FOR_SIZE',1)
+          if status == 2:
             self.addDefine('USE_KBYTES_FOR_SIZE',1)
+          if status == 3:
+            self.addDefine('USE_PAGES_FOR_SIZE',1)
         elif status == 0:
           self.delDefine('HAVE_GETRUSAGE')
           self.framework.logPrint("getrusage() does not work (returns 0)")

src/sys/memory/mem.c

   FILE       *file;
   char       proc[PETSC_MAX_PATH_LEN];
   int        mm,rss,err;
-#elif defined(PETSC_HAVE_TASK_INFO)
-  /*  task_basic_info_data_t ti;
-      unsigned int           count; */
-  /*
-     The next line defined variables that are not used; but if they
-     are not included the code crashes. Something must be wrong
-     with either the task_info() command or compiler corrupting the
-     stack.
-  */
-  /* kern_return_t          kerr; */
 #elif defined(PETSC_HAVE_GETRUSAGE)
   static struct rusage temp;
 #endif
   err  = fclose(file);
   if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fclose() failed on file");
 
-#elif defined(PETSC_HAVE_TASK_INFO)
-  *mem = 0;
-  /* if ((kerr = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&ti,&count)) != KERN_SUCCESS) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Mach system call failed: kern_return_t ",kerr);
-   *mem = (PetscLogDouble) ti.resident_size; */
-
 #elif defined(PETSC_HAVE_GETRUSAGE)
   getrusage(RUSAGE_SELF,&temp);
 #if defined(PETSC_USE_KBYTES_FOR_SIZE)
   *mem = 1024.0 * ((PetscLogDouble)temp.ru_maxrss);
-#elif defined(PETSC_HAVE_GETPAGESIZE)
+#elif defined(PETSC_USE_PAGES_FOR_SIZE) && defined(PETSC_HAVE_GETPAGESIZE)
   *mem = ((PetscLogDouble)getpagesize())*((PetscLogDouble)temp.ru_maxrss);
 #else
-  *mem = 0.0;
+  *mem = temp.ru_maxrss;
 #endif
 
 #else
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.