Date: 2016-07-24T16:47:37+00:00

Actual source code: pname.c
petsc-3.7.3 2016-07-24
Report Typos and Errors

      2: #include <petsc/private/petscimpl.h>        /*I    "petscsys.h"   I*/
      3: #include <petscviewer.h>

      7: /*@C
      8:    PetscObjectSetName - Sets a string name associated with a PETSc object.

     10:    Not Collective

     12:    Input Parameters:
     13: +  obj - the Petsc variable
     14:          Thus must be cast with a (PetscObject), for example,
     15:          PetscObjectSetName((PetscObject)mat,name);
     16: -  name - the name to give obj

     18:    Level: advanced

     20:    Concepts: object name^setting

     22: .seealso: PetscObjectGetName()
     23: @*/
     24: PetscErrorCode  PetscObjectSetName(PetscObject obj,const char name[])
     25: {

     30:   PetscFree(obj->name);
     31:   PetscStrallocpy(name,&obj->name);
     32:   return(0);
     33: }

     37: /*@C
     38:       PetscObjectPrintTypeNamePrefix - used in the XXXView() methods to display information about the class, name, prefix and type of an object

     40:    Input Parameters:
     41: +     obj - the PETSc object
     42: -     viewer - ASCII viewer where the information is printed, function does nothing if the viewer is not PETSCVIEWERASCII type

     44:    Level: developer

     46:    Notes: If the viewer format is PETSC_VIEWER_ASCII_MATLAB then the information is printed after a % symbol
     47:           so that MATLAB will treat it as a comment.

     49:           If the viewer format is PETSC_VIEWER_ASCII_VTK*, PETSC_VIEWER_ASCII_LATEX, or
     50:           PETSC_VIEWER_ASCII_MATRIXMARKET then don't print header information
     51:           as these formats can't process it.

     53: .seealso: PetscObjectSetName(), PetscObjectName()

     55: @*/
     56: PetscErrorCode PetscObjectPrintClassNamePrefixType(PetscObject obj,PetscViewer viewer)
     57: {
     58:   PetscErrorCode    ierr;
     59:   MPI_Comm          comm;
     60:   PetscMPIInt       size;
     61:   PetscViewerFormat format;
     62:   PetscBool         flg;

     65:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&flg);
     66:   if (!flg) return(0);

     68:   PetscViewerGetFormat(viewer,&format);
     69:   if (format == PETSC_VIEWER_ASCII_VTK || format == PETSC_VIEWER_ASCII_VTK_CELL || format == PETSC_VIEWER_ASCII_VTK_COORDS || format == PETSC_VIEWER_ASCII_MATRIXMARKET || format == PETSC_VIEWER_ASCII_LATEX) return(0);

     71:   if (format == PETSC_VIEWER_ASCII_MATLAB) {PetscViewerASCIIPrintf(viewer,"%%");}
     72:   PetscViewerASCIIPrintf(viewer,"%s Object:",obj->class_name);
     73:   if (obj->name) {
     74:     PetscViewerASCIIPrintf(viewer,"%s",obj->name);
     75:   }
     76:   if (obj->prefix) {
     77:     PetscViewerASCIIPrintf(viewer,"(%s)",obj->prefix);
     78:   }
     79:   PetscObjectGetComm(obj,&comm);
     80:   MPI_Comm_size(comm,&size);
     81:   PetscViewerASCIIPrintf(viewer," %d MPI processes\n",size);
     82:   if (format == PETSC_VIEWER_ASCII_MATLAB) {PetscViewerASCIIPrintf(viewer,"%%");}
     83:   if (obj->type_name) {
     84:     PetscViewerASCIIPrintf(viewer,"  type: %s\n",obj->type_name);
     85:   } else {
     86:     PetscViewerASCIIPrintf(viewer,"  type not yet set\n");
     87:   }
     88:   return(0);
     89: }

     93: /*@C
     94:    PetscObjectName - Gives an object a name if it does not have one

     96:    Collective

     98:    Input Parameters:
     99: .  obj - the Petsc variable
    100:          Thus must be cast with a (PetscObject), for example,
    101:          PetscObjectName((PetscObject)mat,name);

    103:    Level: developer

    105:    Concepts: object name^setting default

    107:    Notes: This is used in a small number of places when an object NEEDS a name, for example when it is saved to MATLAB with that variable name.
    108:           Use PetscObjectSetName() to set the name of an object to what you want. The SAWs viewer requires that no two published objects
    109:           share the same name.

    111:    Developer Note: this needs to generate the exact same string on all ranks that share the object. The current algorithm may not always work.

    115: .seealso: PetscObjectGetName(), PetscObjectSetName()
    116: @*/
    117: PetscErrorCode  PetscObjectName(PetscObject obj)
    118: {
    119:   PetscErrorCode   ierr;
    120:   PetscCommCounter *counter;
    121:   PetscMPIInt      flg;
    122:   char             name[64];

    126:   if (!obj->name) {
    127:     union {MPI_Comm comm; void *ptr; char raw[sizeof(MPI_Comm)]; } ucomm;
    128:     MPI_Attr_get(obj->comm,Petsc_Counter_keyval,(void*)&counter,&flg);
    129:     if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Bad MPI communicator supplied; must be a PETSc communicator");
    130:     ucomm.ptr = NULL;
    131:     ucomm.comm = obj->comm;
    132:     MPI_Bcast(ucomm.raw,sizeof(MPI_Comm),MPI_BYTE,0,obj->comm);
    133:     /* If the union has extra bytes, their value is implementation-dependent, but they will normally be what we set last
    134:      * in 'ucomm.ptr = NULL'.  This output is always implementation-defined (and varies from run to run) so the union
    135:      * abuse acceptable. */
    136:     PetscSNPrintf(name,64,"%s_%p_%D",obj->class_name,ucomm.ptr,counter->namecount++);
    137:     PetscStrallocpy(name,&obj->name);
    138:   }
    139:   return(0);
    140: }

    146: PetscErrorCode  PetscObjectChangeTypeName(PetscObject obj,const char type_name[])
    147: {

    152:   PetscFree(obj->type_name);
    153:   PetscStrallocpy(type_name,&obj->type_name);
    154:   /* Clear all the old subtype callbacks so they can't accidentally be called (shouldn't happen anyway) */
    155:   PetscMemzero(obj->fortrancallback[PETSC_FORTRAN_CALLBACK_SUBTYPE],obj->num_fortrancallback[PETSC_FORTRAN_CALLBACK_SUBTYPE]*sizeof(PetscFortranCallback));
    156:   return(0);
    157: }