Actual source code: pname.c
petsc-3.3-p7 2013-05-11
2: #include <petscsys.h> /*I "petscsys.h" I*/
6: /*@C
7: PetscObjectSetName - Sets a string name associated with a PETSc object.
9: Not Collective
11: Input Parameters:
12: + obj - the Petsc variable
13: Thus must be cast with a (PetscObject), for example,
14: PetscObjectSetName((PetscObject)mat,name);
15: - name - the name to give obj
17: Level: advanced
19: Concepts: object name^setting
21: .seealso: PetscObjectGetName()
22: @*/
23: PetscErrorCode PetscObjectSetName(PetscObject obj,const char name[])
24: {
29: PetscFree(obj->name);
30: PetscStrallocpy(name,&obj->name);
31: return(0);
32: }
36: /*@C
37: PetscObjectPrintTypeNamePrefix - used in the XXXView() methods to display information about the class, name, prefix and type of an object
39: Input Parameters:
40: + obj - the PETSc object
41: . viewer - ASCII viewer where the information is printed
42: - string - for example "Matrix Object"
44: Level: developer
46: .seealso: PetscObjectSetName(), PetscObjectName()
48: @*/
49: PetscErrorCode PetscObjectPrintClassNamePrefixType(PetscObject obj,PetscViewer viewer,const char string[])
50: {
52: MPI_Comm comm;
53: PetscMPIInt size;
56: PetscViewerASCIIPrintf(viewer,"%s:",string);
57: if (obj->name) {
58: PetscViewerASCIIPrintf(viewer,"%s",obj->name);
59: }
60: if (obj->prefix) {
61: PetscViewerASCIIPrintf(viewer,"(%s)",obj->prefix);
62: }
63: PetscObjectGetComm(obj,&comm);
64: MPI_Comm_size(comm,&size);
65: PetscViewerASCIIPrintf(viewer," %d MPI processes\n",size);
66: if (obj->type_name) {
67: PetscViewerASCIIPrintf(viewer," type: %s\n",obj->type_name);
68: } else {
69: PetscViewerASCIIPrintf(viewer," type not yet set\n");
70: }
71: return(0);
72: }
76: /*@C
77: PetscObjectName - Gives an object a name if it does not have one
79: Collective
81: Input Parameters:
82: . obj - the Petsc variable
83: Thus must be cast with a (PetscObject), for example,
84: PetscObjectName((PetscObject)mat,name);
86: Level: developer
88: Concepts: object name^setting default
90: 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.
91: Use PetscObjectSetName() to set the name of an object to what you want. The AMS viewer requires that no two published objects
92: share the same name.
94: Developer Note: this needs to generate the exact same string on all ranks that share the object. The current algorithm may not always work.
98: .seealso: PetscObjectGetName(), PetscObjectSetName()
99: @*/
100: PetscErrorCode PetscObjectName(PetscObject obj)
101: {
102: PetscErrorCode ierr;
103: PetscCommCounter *counter;
104: PetscMPIInt flg;
105: char name[64];
109: if (!obj->name) {
110: void *commp = 0;
111: MPI_Attr_get(obj->comm,Petsc_Counter_keyval,(void*)&counter,&flg);
112: if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Bad MPI communicator supplied; must be a PETSc communicator");
113: PetscMemcpy(&commp,&obj->comm,PetscMin(sizeof(commp),sizeof(obj->comm)));
114: MPI_Bcast(&commp,1,MPIU_SIZE_T,0,obj->comm);
115: PetscSNPrintf(name,64,"%s_%p_%D",obj->class_name,commp,counter->namecount++);
116: PetscStrallocpy(name,&obj->name);
117: }
118: return(0);
119: }
125: PetscErrorCode PetscObjectChangeTypeName(PetscObject obj,const char type_name[])
126: {
131: PetscObjectTakeAccess(obj);
132: PetscFree(obj->type_name);
133: PetscStrallocpy(type_name,&obj->type_name);
134: PetscObjectGrantAccess(obj);
135: return(0);
136: }