Commits

BarryFSmith committed 1c6c1b7

cleanup of AMS viewer, handle JSON-RPC multiple Comms

Comments (0)

Files changed (8)

include/petscviewerams.h

-/*
-     PetscViewers are objects where other objects can be looked at or stored.
-*/
 
 #if !defined(__PETSCVIEWERAMS_H)
 #define __PETSCVIEWERAMS_H
 PETSC_EXTERN PetscErrorCode PetscViewerAMSSetCommName(PetscViewer,const char[]);
 PETSC_EXTERN PetscErrorCode PetscViewerAMSGetAMSComm(PetscViewer,AMS_Comm *);
 PETSC_EXTERN PetscErrorCode PetscViewerAMSOpen(MPI_Comm,const char[],PetscViewer*);
-PETSC_EXTERN PetscErrorCode PetscViewerAMSLock(PetscViewer);
 PETSC_EXTERN PetscViewer    PETSC_VIEWER_AMS_(MPI_Comm);
 PETSC_EXTERN PetscErrorCode PETSC_VIEWER_AMS_Destroy(MPI_Comm);
 #define PETSC_VIEWER_AMS_WORLD PETSC_VIEWER_AMS_(PETSC_COMM_WORLD)
+#define PETSC_VIEWER_AMS_SELF  PETSC_VIEWER_AMS_(PETSC_COMM_SELF)
 
 #endif

include/web/AMSJavascript.html

 <iframe id="__pygwt_historyFrame" style="display:none;"></iframe>
 <script type="text/javascript" src="bootstrap.js"></script>
 <iframe id="__pygwt_historyFrame" style="display:none;"></iframe>
+<script type="text/javascript" src="bootstrap.js"></script>
+<iframe id="__pygwt_historyFrame" style="display:none;"></iframe>
+<script type="text/javascript" src="bootstrap.js"></script>
+<iframe id="__pygwt_historyFrame" style="display:none;"></iframe>
+<script type="text/javascript" src="bootstrap.js"></script>
+<iframe id="__pygwt_historyFrame" style="display:none;"></iframe>
+<script type="text/javascript" src="bootstrap.js"></script>
+<iframe id="__pygwt_historyFrame" style="display:none;"></iframe>
+<script type="text/javascript" src="bootstrap.js"></script>
+<iframe id="__pygwt_historyFrame" style="display:none;"></iframe>
+<script type="text/javascript" src="bootstrap.js"></script>
+<iframe id="__pygwt_historyFrame" style="display:none;"></iframe>
 </body>
 </html>

include/web/AMSJavascript.py

         method = str(request_info.method)
         rid    = request_info.id
         if method == "YAML_AMS_Connect":
-            self.commname = str(response)
+            if isinstance(response,list):
+              self.commname = str(response[1])
+            else:
+              self.commname = str(response)
             if self.commname == 'No AMS publisher running':
                  pass
             else:

src/ksp/ksp/interface/itcl.c

     ierr = KSPMonitorSet(ksp,KSPMonitorLGRange,ctx,(PetscErrorCode (*)(void**))PetscViewerDestroy);CHKERRQ(ierr);
   }
 
+#if defined(PETSC_HAVE_AMS)
   /*
     Publishes convergence information using AMS
   */
     ierr = KSPMonitorSet(ksp,KSPMonitorAMS,ctx,KSPMonitorAMSDestroy);CHKERRQ(ierr);
     ierr = KSPSetComputeSingularValues(ksp,PETSC_TRUE);CHKERRQ(ierr);
   }
+#endif
 
   /* -----------------------------------------------------------------------*/
   ierr = KSPSetUpNorms_Private(ksp,&normtype,&pcside);CHKERRQ(ierr);

src/ksp/ksp/interface/kspams.c

 
   PetscFunctionBegin;
   ierr = PetscNewLog(ksp,KSPMonitor_AMS,&mon);CHKERRQ(ierr);
-#if defined(PETSC_HAVE_AMS)
   ierr      = PetscViewerAMSOpen(PetscObjectComm((PetscObject)ksp),amscommname,&mon->viewer);CHKERRQ(ierr);
   mon->amem = -1;
-#endif
   *ctx = (void*)mon;
   PetscFunctionReturn(0);
 }
   PetscErrorCode ierr;
 
   PetscFunctionBegin;
-#if defined(PETSC_HAVE_AMS)
   if (mon->amem != -1) {
     ierr      = AMS_Memory_destroy(mon->amem);CHKERRQ(ierr);
     mon->amem = -1;
   }
-#endif
   ierr      = PetscViewerDestroy(&mon->viewer);CHKERRQ(ierr);
   ierr      = PetscFree(mon->eigr);CHKERRQ(ierr);
   mon->eigi = NULL;
 @*/
 PetscErrorCode KSPMonitorAMS(KSP ksp,PetscInt n,PetscReal rnorm,void *ctx)
 {
-#if defined(PETSC_HAVE_AMS)
   PetscErrorCode ierr;
   KSPMonitor_AMS *mon   = (KSPMonitor_AMS*)ctx;
   PetscViewer    viewer = mon->viewer;
 
   ierr = PetscInfo2(ksp,"KSP extreme singular values min=%G max=%G\n",emin,emax);CHKERRQ(ierr);
   PetscFunctionReturn(0);
-#else
-  PetscFunctionBegin;
-  SETERRQ(PetscObjectComm((PetscObject)ksp),PETSC_ERR_SUP,"Missing package AMS");
-  PetscFunctionReturn(0);
-#endif
 }
 #endif

src/sys/classes/viewer/impls/ams/ams.c

 
 #include <petsc-private/viewerimpl.h>
+#include <petscviewerams.h>
 #include <petscsys.h>
 
-#include <ams.h>
 typedef struct {
   char     *ams_name;
   AMS_Comm ams_comm;
   Concepts: AMS^getting communicator
   Concepts: communicator^accessing AMS communicator
 
-.seealso: PetscViewerDestroy(), PetscViewerAMSOpen(), PetscViewer_AMS_, PetscViewer_AMS_WORLD, PetscViewer_AMS_SELF
+.seealso: PetscViewerDestroy(), PetscViewerAMSOpen(), PETSC_VIEWER_AMS_, PETSC_VIEWER_AMS_WORLD, PETSC_VIEWER_AMS_SELF
 
 @*/
 PetscErrorCode PetscViewerAMSGetAMSComm(PetscViewer v,AMS_Comm *ams_comm)
      an error code.  The window PetscViewer is usually used in the form
 $       XXXView(XXX object,PETSC_VIEWER_AMS_(comm));
 
-.seealso: PetscViewer_AMS_WORLD, PetscViewer_AMS_SELF, PetscViewerAMSOpen(),
+.seealso: PETSC_VIEWER_AMS_WORLD, PETSC_VIEWER_AMS_SELF
 @*/
 PetscViewer PETSC_VIEWER_AMS_(MPI_Comm comm)
 {

src/sys/classes/viewer/impls/ams/amsopen.c

 
 #include <petsc-private/viewerimpl.h>   /*I  "petscsys.h"  */
+#include <petscviewerams.h>
 
 #undef __FUNCT__
 #define __FUNCT__ "PetscViewerAMSOpen"
     Notes:
     This PetscViewer can be destroyed with PetscViewerDestroy().
 
+    This viewer is currently different than other viewers in that you cannot pass this viewer to XXXView() to view the XXX object.
+    PETSC_VIEWER_AMS_() is used by PetscObjectAMSPublish() to connect to that particular AMS communicator.
+
     Information about the AMS is available via http://www.mcs.anl.gov/ams.
 
    Concepts: AMS
    Concepts: ALICE Memory Snooper
    Concepts: Asynchronous Memory Snooper
 
-.seealso: PetscObjectAMSPublish(), PetscViewerDestroy(), PetscViewerStringSPrintf()
+.seealso: PetscObjectAMSPublish(), PetscViewerDestroy(), PetscViewerStringSPrintf(), PETSC_VIEWER_AMS_(),
+          PetscObjectAMSPublish(), PetscObjectAMSUnPublish(), PetscObjectAMSTakeAccess(), PetscObjectAMSGrantAccess()
 
 @*/
 PetscErrorCode PetscViewerAMSOpen(MPI_Comm comm,const char name[],PetscViewer *lab)

src/sys/classes/viewer/impls/socket/send.c

 */
 
 #undef __FUNCT__
+#define __FUNCT__ "YAML_AMS_Utility_ArrayToString"
+static PetscErrorCode YAML_AMS_Utility_ArrayToString(PetscInt n,void *addr,AMS_Data_type dtype,char **result)
+{
+  PetscErrorCode ierr;
+
+  PetscFunctionBegin;
+  if (n == 1) {
+    if (dtype == AMS_STRING) {
+      ierr = PetscStrallocpy(*(const char**)addr,result);CHKERRQ(ierr);
+    } else if (dtype == AMS_DOUBLE) {
+      ierr = PetscMalloc(20*sizeof(char),result);CHKERRQ(ierr);
+      sprintf(*result,"%18.16e",*(double*)addr);
+    } else if (dtype == AMS_INT) {
+      ierr = PetscMalloc(10*sizeof(char),result);CHKERRQ(ierr);
+      sprintf(*result,"%d",*(int*)addr);
+    } else if (dtype == AMS_BOOLEAN) {
+      if (*(PetscBool*)addr) {
+        ierr = PetscStrallocpy("true",result);CHKERRQ(ierr);
+      } else {
+        ierr = PetscStrallocpy("false",result);CHKERRQ(ierr);
+      }
+    } else {
+      ierr = PetscStrallocpy("Not yet done",result);CHKERRQ(ierr);
+    }
+  } else {
+    PetscInt i;
+    size_t   len = 0,lent;
+    char     buff[25],**array = (char**)addr;
+
+    if (dtype == AMS_STRING) {
+      for (i=0; i<n; i++) {
+        ierr = PetscStrlen(array[i],&lent);CHKERRQ(ierr);
+        len += lent + 3;
+      }
+      ierr = PetscMalloc(len*sizeof(char),result);CHKERRQ(ierr);
+      ierr = PetscStrcpy(*result,"[\"");CHKERRQ(ierr);
+      for (i=0; i<n-1; i++) {
+        ierr = PetscStrcat(*result,array[i]);CHKERRQ(ierr);
+        ierr = PetscStrcat(*result,"\",\"");CHKERRQ(ierr);
+      }
+      ierr = PetscStrcat(*result,array[n-1]);CHKERRQ(ierr);
+      ierr = PetscStrcat(*result,"\"]");CHKERRQ(ierr);
+    } else if (dtype == AMS_DOUBLE) {
+      ierr = PetscMalloc(30*n*sizeof(char),result);CHKERRQ(ierr);
+      ierr = PetscStrcpy(*result,"[\"");CHKERRQ(ierr);
+      for (i=0; i<n-1; i++) {
+        sprintf(buff,"%18.16e",*(double*)addr);
+        ierr = PetscStrcat(*result,buff);CHKERRQ(ierr);
+        ierr = PetscStrcat(*result,"\",\"");CHKERRQ(ierr);
+        addr = (void *) ((char *)addr + sizeof(PetscReal));
+      }
+      sprintf(buff,"%18.16e",*(double*)addr);
+      ierr = PetscStrcat(*result,buff);CHKERRQ(ierr);
+      ierr = PetscStrcat(*result,"\"]");CHKERRQ(ierr);
+    } else if (dtype == AMS_INT) {
+      ierr = PetscMalloc(13*n*sizeof(char),result);CHKERRQ(ierr);
+      ierr = PetscStrcpy(*result,"[\"");CHKERRQ(ierr);
+      for (i=0; i<n-1; i++) {
+        sprintf(buff,"%d",*(int*)addr);
+        ierr = PetscStrcat(*result,buff);CHKERRQ(ierr);
+        ierr = PetscStrcat(*result,"\",\"");CHKERRQ(ierr);
+        addr = (void *) ((char *)addr + sizeof(PetscInt));
+      }
+      sprintf(buff,"%d",*(int*)addr);
+      ierr = PetscStrcat(*result,buff);CHKERRQ(ierr);
+      ierr = PetscStrcat(*result,"\"]");CHKERRQ(ierr);
+    } else if (dtype == AMS_BOOLEAN) {
+      ierr = PetscMalloc(7*n*sizeof(char),result);CHKERRQ(ierr);
+      ierr = PetscStrcpy(*result,"[\"");CHKERRQ(ierr);
+      for (i=0; i<n-1; i++) {
+      ierr = PetscStrcat(*result,*(PetscBool*)addr ? "true" : "false");CHKERRQ(ierr);
+        addr = (void *) ((char *)addr + sizeof(int));
+      }
+      ierr = PetscStrcat(*result,*(PetscBool*)addr ? "true" : "false");CHKERRQ(ierr);
+      ierr = PetscStrcat(*result,"\"]");CHKERRQ(ierr);
+    } else {
+      ierr = PetscStrallocpy("Not yet done",result);CHKERRQ(ierr);
+    }
+  }
+  PetscFunctionReturn(0);
+}
+
+#undef __FUNCT__
 #define __FUNCT__ "YAML_AMS_Connect"
 /*
       Connects to the local AMS and gets only the first communication name
 {
   PetscErrorCode ierr;
   char           **list = 0;
+  PetscInt       n = 0;
 
   PetscFunctionBegin;
   ierr = AMS_Connect(0,-1,&list);
   *argco = 1;
   ierr   = PetscMalloc(sizeof(char*),argso);CHKERRQ(ierr);
   if (list) {
-    ierr = PetscStrallocpy(list[0],&(*argso)[0]);CHKERRQ(ierr);
+    while (list[n]) n++;
+    ierr = YAML_AMS_Utility_ArrayToString(n,list,AMS_STRING,&(*argso)[0]);CHKERRQ(ierr);
   } else {
     ierr = PetscStrallocpy("No AMS publisher running",&(*argso)[0]);CHKERRQ(ierr);
   }
 const char *AMS_Shared_types[] = {"AMS_SHARED_UNDEF","AMS_COMMON","AMS_REDUCED","AMS_DISTRIBUTED","AMS_Shared_type","AMS_",0};
 const char *AMS_Reduction_types[] = {"AMS_REDUCTION_WHY_NOT_UNDEF?","AMS_SUM","AMS_MAX","AMS_MIN","AMS_REDUCTION_UNDEF","AMS_Reduction_type","AMS_",0};
 
-#undef __FUNCT__
-#define __FUNCT__ "YAML_AMS_Utility_ArrayToString"
-static PetscErrorCode YAML_AMS_Utility_ArrayToString(PetscInt n,void *addr,AMS_Data_type dtype,char **result)
-{
-  PetscErrorCode ierr;
-
-  PetscFunctionBegin;
-  if (n == 1) {
-    if (dtype == AMS_STRING) {
-      ierr = PetscStrallocpy(*(const char**)addr,result);CHKERRQ(ierr);
-    } else if (dtype == AMS_DOUBLE) {
-      ierr = PetscMalloc(20*sizeof(char),result);CHKERRQ(ierr);
-      sprintf(*result,"%18.16e",*(double*)addr);
-    } else if (dtype == AMS_INT) {
-      ierr = PetscMalloc(10*sizeof(char),result);CHKERRQ(ierr);
-      sprintf(*result,"%d",*(int*)addr);
-    } else if (dtype == AMS_BOOLEAN) {
-      if (*(PetscBool*)addr) {
-        ierr = PetscStrallocpy("true",result);CHKERRQ(ierr);
-      } else {
-        ierr = PetscStrallocpy("false",result);CHKERRQ(ierr);
-      }
-    } else {
-      ierr = PetscStrallocpy("Not yet done",result);CHKERRQ(ierr);
-    }
-  } else {
-    PetscInt i;
-    size_t   len = 0,lent;
-    char     buff[25],**array = (char**)addr;
-
-    if (dtype == AMS_STRING) {
-      for (i=0; i<n; i++) {
-        ierr = PetscStrlen(array[i],&lent);CHKERRQ(ierr);
-        len += lent + 3;
-      }
-      ierr = PetscMalloc(len*sizeof(char),result);CHKERRQ(ierr);
-      ierr = PetscStrcpy(*result,"[\"");CHKERRQ(ierr);
-      for (i=0; i<n-1; i++) {
-        ierr = PetscStrcat(*result,array[i]);CHKERRQ(ierr);
-        ierr = PetscStrcat(*result,"\",\"");CHKERRQ(ierr);
-      }
-      ierr = PetscStrcat(*result,array[n-1]);CHKERRQ(ierr);
-      ierr = PetscStrcat(*result,"\"]");CHKERRQ(ierr);
-    } else if (dtype == AMS_DOUBLE) {
-      ierr = PetscMalloc(30*n*sizeof(char),result);CHKERRQ(ierr);
-      ierr = PetscStrcpy(*result,"[\"");CHKERRQ(ierr);
-      for (i=0; i<n-1; i++) {
-        sprintf(buff,"%18.16e",*(double*)addr);
-        ierr = PetscStrcat(*result,buff);CHKERRQ(ierr);
-        ierr = PetscStrcat(*result,"\",\"");CHKERRQ(ierr);
-        addr = (void *) ((char *)addr + sizeof(PetscReal));
-      }
-      sprintf(buff,"%18.16e",*(double*)addr);
-      ierr = PetscStrcat(*result,buff);CHKERRQ(ierr);
-      ierr = PetscStrcat(*result,"\"]");CHKERRQ(ierr);
-    } else if (dtype == AMS_INT) {
-      ierr = PetscMalloc(13*n*sizeof(char),result);CHKERRQ(ierr);
-      ierr = PetscStrcpy(*result,"[\"");CHKERRQ(ierr);
-      for (i=0; i<n-1; i++) {
-        sprintf(buff,"%d",*(int*)addr);
-        ierr = PetscStrcat(*result,buff);CHKERRQ(ierr);
-        ierr = PetscStrcat(*result,"\",\"");CHKERRQ(ierr);
-        addr = (void *) ((char *)addr + sizeof(PetscInt));
-      }
-      sprintf(buff,"%d",*(int*)addr);
-      ierr = PetscStrcat(*result,buff);CHKERRQ(ierr);
-      ierr = PetscStrcat(*result,"\"]");CHKERRQ(ierr);
-    } else if (dtype == AMS_BOOLEAN) {
-      ierr = PetscMalloc(7*n*sizeof(char),result);CHKERRQ(ierr);
-      ierr = PetscStrcpy(*result,"[\"");CHKERRQ(ierr);
-      for (i=0; i<n-1; i++) {
-      ierr = PetscStrcat(*result,*(PetscBool*)addr ? "true" : "false");CHKERRQ(ierr);
-        addr = (void *) ((char *)addr + sizeof(int));
-      }
-      ierr = PetscStrcat(*result,*(PetscBool*)addr ? "true" : "false");CHKERRQ(ierr);
-      ierr = PetscStrcat(*result,"\"]");CHKERRQ(ierr);
-    } else {
-      ierr = PetscStrallocpy("Not yet done",result);CHKERRQ(ierr);
-    }
-  }
-  PetscFunctionReturn(0);
-}
 
 #undef __FUNCT__
 #define __FUNCT__ "YAML_AMS_Memory_get_field_info"
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.