Date: 2013-07-02T14:38:51+00:00

Actual source code: pname.c
petsc-3.4.2 2013-07-02

      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
     43: -     string - for example "Matrix Object"

     45:    Level: developer

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

     49: @*/
     50: PetscErrorCode PetscObjectPrintClassNamePrefixType(PetscObject obj,PetscViewer viewer,const char string[])
     51: {
     53:   MPI_Comm       comm;
     54:   PetscMPIInt    size;

     57:   PetscViewerASCIIPrintf(viewer,"%s:",string);
     58:   if (obj->name) {
     59:     PetscViewerASCIIPrintf(viewer,"%s",obj->name);
     60:   }
     61:   if (obj->prefix) {
     62:     PetscViewerASCIIPrintf(viewer,"(%s)",obj->prefix);
     63:   }
     64:   PetscObjectGetComm(obj,&comm);
     65:   MPI_Comm_size(comm,&size);
     66:   PetscViewerASCIIPrintf(viewer," %d MPI processes\n",size);
     67:   if (obj->type_name) {
     68:     PetscViewerASCIIPrintf(viewer,"  type: %s\n",obj->type_name);
     69:   } else {
     70:     PetscViewerASCIIPrintf(viewer,"  type not yet set\n");
     71:   }
     72:   return(0);
     73: }

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

     80:    Collective

     82:    Input Parameters:
     83: .  obj - the Petsc variable
     84:          Thus must be cast with a (PetscObject), for example,
     85:          PetscObjectName((PetscObject)mat,name);

     87:    Level: developer

     89:    Concepts: object name^setting default

     91:    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.
     92:           Use PetscObjectSetName() to set the name of an object to what you want. The AMS viewer requires that no two published objects
     93:           share the same name.

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

     99: .seealso: PetscObjectGetName(), PetscObjectSetName()
    100: @*/
    101: PetscErrorCode  PetscObjectName(PetscObject obj)
    102: {
    103:   PetscErrorCode   ierr;
    104:   PetscCommCounter *counter;
    105:   PetscMPIInt      flg;
    106:   char             name[64];

    110:   if (!obj->name) {
    111:     union {MPI_Comm comm; void *ptr; char raw[sizeof(MPI_Comm)]; } ucomm;
    112:     MPI_Attr_get(obj->comm,Petsc_Counter_keyval,(void*)&counter,&flg);
    113:     if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Bad MPI communicator supplied; must be a PETSc communicator");
    114:     ucomm.ptr = NULL;
    115:     ucomm.comm = obj->comm;
    116:     MPI_Bcast(ucomm.raw,sizeof(MPI_Comm),MPI_BYTE,0,obj->comm);
    117:     /* If the union has extra bytes, their value is implementation-dependent, but they will normally be what we set last
    118:      * in 'ucomm.ptr = NULL'.  This output is always implementation-defined (and varies from run to run) so the union
    119:      * abuse acceptable. */
    120:     PetscSNPrintf(name,64,"%s_%p_%D",obj->class_name,ucomm.ptr,counter->namecount++);
    121:     PetscStrallocpy(name,&obj->name);
    122:   }
    123:   return(0);
    124: }

    130: PetscErrorCode  PetscObjectChangeTypeName(PetscObject obj,const char type_name[])
    131: {

    136:   PetscFree(obj->type_name);
    137:   PetscStrallocpy(type_name,&obj->type_name);
    138:   /* Clear all the old subtype callbacks so they can't accidentally be called (shouldn't happen anyway) */
    139:   PetscMemzero(obj->fortrancallback[PETSC_FORTRAN_CALLBACK_SUBTYPE],obj->num_fortrancallback[PETSC_FORTRAN_CALLBACK_SUBTYPE]*sizeof(PetscFortranCallback));
    140:   return(0);
    141: }