xref: /petsc/src/sys/objects/gcomm.c (revision d8d19677bbccf95218448bee62e6b87f4513e133)
17d0a6c19SBarry Smith 
2e5c89e4eSSatish Balay /*
3e5c89e4eSSatish Balay      Provides utility routines for manulating any type of PETSc object.
4e5c89e4eSSatish Balay */
5af0996ceSBarry Smith #include <petsc/private/petscimpl.h>  /*I   "petscsys.h"    I*/
6e5c89e4eSSatish Balay 
7ce94432eSBarry Smith /*@C
8ce94432eSBarry Smith    PetscObjectComm - Gets the MPI communicator for any PetscObject   regardless of the type.
9ce94432eSBarry Smith 
10ce94432eSBarry Smith    Not Collective
11ce94432eSBarry Smith 
12ce94432eSBarry Smith    Input Parameter:
13ce94432eSBarry Smith .  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
14ce94432eSBarry Smith          cast with a (PetscObject), for example,
15ce94432eSBarry Smith          SETERRQ(PetscObjectComm((PetscObject)mat,...);
16ce94432eSBarry Smith 
17ce94432eSBarry Smith    Output Parameter:
18ce94432eSBarry Smith .  comm - the MPI communicator or MPI_COMM_NULL if object is not valid
19ce94432eSBarry Smith 
20ce94432eSBarry Smith    Level: advanced
21ce94432eSBarry Smith 
2295452b02SPatrick Sanan    Notes:
2395452b02SPatrick Sanan     Never use this in the form
24ce94432eSBarry Smith $       comm = PetscObjectComm((PetscObject)obj);
25ce94432eSBarry Smith         instead use PetscObjectGetComm()
26ce94432eSBarry Smith 
27ce94432eSBarry Smith .seealso: PetscObjectGetComm()
28ce94432eSBarry Smith @*/
29ce94432eSBarry Smith MPI_Comm  PetscObjectComm(PetscObject obj)
30ce94432eSBarry Smith {
31ce94432eSBarry Smith   if (!obj) return MPI_COMM_NULL;
32ce94432eSBarry Smith   return obj->comm;
33ce94432eSBarry Smith }
34ce94432eSBarry Smith 
35e5c89e4eSSatish Balay /*@C
36e5c89e4eSSatish Balay    PetscObjectGetComm - Gets the MPI communicator for any PetscObject,
37e5c89e4eSSatish Balay    regardless of the type.
38e5c89e4eSSatish Balay 
39e5c89e4eSSatish Balay    Not Collective
40e5c89e4eSSatish Balay 
41e5c89e4eSSatish Balay    Input Parameter:
42e5c89e4eSSatish Balay .  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
43e5c89e4eSSatish Balay          cast with a (PetscObject), for example,
44e5c89e4eSSatish Balay          PetscObjectGetComm((PetscObject)mat,&comm);
45e5c89e4eSSatish Balay 
46e5c89e4eSSatish Balay    Output Parameter:
47e5c89e4eSSatish Balay .  comm - the MPI communicator
48e5c89e4eSSatish Balay 
49e5c89e4eSSatish Balay    Level: advanced
50e5c89e4eSSatish Balay 
51ce94432eSBarry Smith .seealso: PetscObjectComm()
52e5c89e4eSSatish Balay @*/
537087cfbeSBarry Smith PetscErrorCode  PetscObjectGetComm(PetscObject obj,MPI_Comm *comm)
54e5c89e4eSSatish Balay {
55e5c89e4eSSatish Balay   PetscErrorCode ierr;
56e5c89e4eSSatish Balay 
57e5c89e4eSSatish Balay   PetscFunctionBegin;
583cfa8680SLisandro Dalcin   PetscValidHeader(obj,1);
593cfa8680SLisandro Dalcin   PetscValidPointer(comm,2);
60e5c89e4eSSatish Balay   if (obj->bops->getcomm) {
61e5c89e4eSSatish Balay     ierr = obj->bops->getcomm(obj,comm);CHKERRQ(ierr);
62a297a907SKarl Rupp   } else *comm = obj->comm;
63e5c89e4eSSatish Balay   PetscFunctionReturn(0);
64e5c89e4eSSatish Balay }
65e5c89e4eSSatish Balay 
66cbf1b8bfSBarry Smith /*@
671cee3971SBarry Smith    PetscObjectGetTabLevel - Gets the number of tabs that ASCII output for that object use
68e5c89e4eSSatish Balay 
691cee3971SBarry Smith    Not Collective
701cee3971SBarry Smith 
711cee3971SBarry Smith    Input Parameter:
721cee3971SBarry Smith .  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
731cee3971SBarry Smith          cast with a (PetscObject), for example,
741cee3971SBarry Smith          PetscObjectGetComm((PetscObject)mat,&comm);
751cee3971SBarry Smith 
761cee3971SBarry Smith    Output Parameter:
771cee3971SBarry Smith .   tab - the number of tabs
781cee3971SBarry Smith 
791cee3971SBarry Smith    Level: developer
801cee3971SBarry Smith 
8195452b02SPatrick Sanan     Notes:
8295452b02SPatrick Sanan     this is used to manage the output from options that are imbedded in other objects. For example
83a5b23f4aSJose E. Roman       the KSP object inside a SNES object. By indenting each lower level further the hierarchy of objects
841cee3971SBarry Smith       is very clear.
851cee3971SBarry Smith 
861cee3971SBarry Smith .seealso:  PetscObjectIncrementTabLevel()
871cee3971SBarry Smith 
881cee3971SBarry Smith @*/
897087cfbeSBarry Smith PetscErrorCode  PetscObjectGetTabLevel(PetscObject obj,PetscInt *tab)
901cee3971SBarry Smith {
911cee3971SBarry Smith   PetscFunctionBegin;
921cee3971SBarry Smith   PetscValidHeader(obj,1);
931cee3971SBarry Smith   *tab = obj->tablevel;
941cee3971SBarry Smith   PetscFunctionReturn(0);
951cee3971SBarry Smith }
961cee3971SBarry Smith 
97da35de2aSMatthew G Knepley /*@
98da35de2aSMatthew G Knepley    PetscObjectSetTabLevel - Sets the number of tabs that ASCII output for that object use
99da35de2aSMatthew G Knepley 
100da35de2aSMatthew G Knepley    Not Collective
101da35de2aSMatthew G Knepley 
102da35de2aSMatthew G Knepley    Input Parameters:
103da35de2aSMatthew G Knepley +  obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be
104da35de2aSMatthew G Knepley          cast with a (PetscObject), for example,
105da35de2aSMatthew G Knepley          PetscObjectGetComm((PetscObject)mat,&comm);
106da35de2aSMatthew G Knepley -   tab - the number of tabs
107da35de2aSMatthew G Knepley 
108da35de2aSMatthew G Knepley    Level: developer
109da35de2aSMatthew G Knepley 
11095452b02SPatrick Sanan     Notes:
11195452b02SPatrick Sanan     this is used to manage the output from options that are imbedded in other objects. For example
112a5b23f4aSJose E. Roman       the KSP object inside a SNES object. By indenting each lower level further the hierarchy of objects
113da35de2aSMatthew G Knepley       is very clear.
114da35de2aSMatthew G Knepley 
115da35de2aSMatthew G Knepley .seealso:  PetscObjectIncrementTabLevel()
116da35de2aSMatthew G Knepley @*/
117da35de2aSMatthew G Knepley PetscErrorCode  PetscObjectSetTabLevel(PetscObject obj,PetscInt tab)
118da35de2aSMatthew G Knepley {
119da35de2aSMatthew G Knepley   PetscFunctionBegin;
120da35de2aSMatthew G Knepley   PetscValidHeader(obj,1);
121da35de2aSMatthew G Knepley   obj->tablevel = tab;
122da35de2aSMatthew G Knepley   PetscFunctionReturn(0);
123da35de2aSMatthew G Knepley }
124da35de2aSMatthew G Knepley 
125cbf1b8bfSBarry Smith /*@
1261cee3971SBarry Smith    PetscObjectIncrementTabLevel - Sets the number of tabs that ASCII output for that object use based on
1271cee3971SBarry Smith          the tablevel of another object. This should be called immediately after the object is created.
1281cee3971SBarry Smith 
1291cee3971SBarry Smith    Not Collective
1301cee3971SBarry Smith 
131*d8d19677SJose E. Roman    Input Parameters:
1321cee3971SBarry Smith +  obj - any PETSc object where we are changing the tab
1331cee3971SBarry Smith .  oldobj - the object providing the tab
1341cee3971SBarry Smith -  tab - the increment that is added to the old objects tab
1351cee3971SBarry Smith 
1361cee3971SBarry Smith    Level: developer
1371cee3971SBarry Smith 
13895452b02SPatrick Sanan     Notes:
13995452b02SPatrick Sanan     this is used to manage the output from options that are imbedded in other objects. For example
140a5b23f4aSJose E. Roman       the KSP object inside a SNES object. By indenting each lower level further the hierarchy of objects
1411cee3971SBarry Smith       is very clear.
1421cee3971SBarry Smith 
143acdf4722SStefano Zampini .seealso:   PetscObjectSetTabLevel(),  PetscObjectGetTabLevel()
1441cee3971SBarry Smith 
1451cee3971SBarry Smith @*/
1467087cfbeSBarry Smith PetscErrorCode  PetscObjectIncrementTabLevel(PetscObject obj,PetscObject oldobj,PetscInt tab)
1471cee3971SBarry Smith {
1481cee3971SBarry Smith 
1491cee3971SBarry Smith   PetscFunctionBegin;
1501cee3971SBarry Smith   PetscValidHeader(obj,1);
151a297a907SKarl Rupp   if (oldobj) obj->tablevel = oldobj->tablevel + tab;
152a297a907SKarl Rupp   else obj->tablevel = tab;
1531cee3971SBarry Smith   PetscFunctionReturn(0);
1541cee3971SBarry Smith }
155