xref: /petsc/src/sys/dll/reg.c (revision 495ad40fa91dcaa2644026250534b0e4f700e76b)
17d0a6c19SBarry Smith 
2e5c89e4eSSatish Balay /*
3e5c89e4eSSatish Balay     Provides a general mechanism to allow one to register new routines in
4e5c89e4eSSatish Balay     dynamic libraries for many of the PETSc objects (including, e.g., KSP and PC).
5e5c89e4eSSatish Balay */
6c6db04a5SJed Brown #include <petscsys.h>           /*I "petscsys.h" I*/
7e5c89e4eSSatish Balay 
8e5c89e4eSSatish Balay #undef __FUNCT__
9e5c89e4eSSatish Balay #define __FUNCT__ "PetscFListGetPathAndFunction"
107087cfbeSBarry Smith PetscErrorCode  PetscFListGetPathAndFunction(const char name[],char *path[],char *function[])
11e5c89e4eSSatish Balay {
12e5c89e4eSSatish Balay   PetscErrorCode ierr;
13e5c89e4eSSatish Balay   char           work[PETSC_MAX_PATH_LEN],*lfunction;
14e5c89e4eSSatish Balay 
15e5c89e4eSSatish Balay   PetscFunctionBegin;
16fdad003cSJed Brown   ierr = PetscStrncpy(work,name,sizeof work);CHKERRQ(ierr);
17fdad003cSJed Brown   work[sizeof work - 1] = 0;
18e5c89e4eSSatish Balay   ierr = PetscStrchr(work,':',&lfunction);CHKERRQ(ierr);
19e5c89e4eSSatish Balay   if (lfunction != work && lfunction && lfunction[1] != ':') {
20e5c89e4eSSatish Balay     lfunction[0] = 0;
21e5c89e4eSSatish Balay     ierr = PetscStrallocpy(work,path);CHKERRQ(ierr);
22e5c89e4eSSatish Balay     ierr = PetscStrallocpy(lfunction+1,function);CHKERRQ(ierr);
23e5c89e4eSSatish Balay   } else {
24e5c89e4eSSatish Balay     *path = 0;
25e5c89e4eSSatish Balay     ierr = PetscStrallocpy(name,function);CHKERRQ(ierr);
26e5c89e4eSSatish Balay   }
27e5c89e4eSSatish Balay   PetscFunctionReturn(0);
28e5c89e4eSSatish Balay }
29e5c89e4eSSatish Balay 
303fa76a5bSLisandro Dalcin /*
313fa76a5bSLisandro Dalcin     This is the default list used by PETSc with the PetscDLLibrary register routines
323fa76a5bSLisandro Dalcin */
33d44a1e48SBarry Smith PetscDLLibrary PetscDLLibrariesLoaded = 0;
343fa76a5bSLisandro Dalcin 
35ebd79076SLisandro Dalcin #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
36ebd79076SLisandro Dalcin 
37e5c89e4eSSatish Balay #undef __FUNCT__
38487e5849SBarry Smith #define __FUNCT__ "PetscLoadDynamicLibrary"
397087cfbeSBarry Smith static PetscErrorCode  PetscLoadDynamicLibrary(const char *name,PetscBool  *found)
40487e5849SBarry Smith {
41487e5849SBarry Smith   char           libs[PETSC_MAX_PATH_LEN],dlib[PETSC_MAX_PATH_LEN];
42487e5849SBarry Smith   PetscErrorCode ierr;
43487e5849SBarry Smith 
44487e5849SBarry Smith   PetscFunctionBegin;
45487e5849SBarry Smith   ierr = PetscStrcpy(libs,"${PETSC_LIB_DIR}/libpetsc");CHKERRQ(ierr);
46487e5849SBarry Smith   ierr = PetscStrcat(libs,name);CHKERRQ(ierr);
47487e5849SBarry Smith   ierr = PetscDLLibraryRetrieve(PETSC_COMM_WORLD,libs,dlib,1024,found);CHKERRQ(ierr);
48487e5849SBarry Smith   if (*found) {
49d44a1e48SBarry Smith     ierr = PetscDLLibraryAppend(PETSC_COMM_WORLD,&PetscDLLibrariesLoaded,dlib);CHKERRQ(ierr);
50487e5849SBarry Smith   } else {
51487e5849SBarry Smith     ierr = PetscStrcpy(libs,"${PETSC_DIR}/${PETSC_ARCH}/lib/libpetsc");CHKERRQ(ierr);
52487e5849SBarry Smith     ierr = PetscStrcat(libs,name);CHKERRQ(ierr);
53487e5849SBarry Smith     ierr = PetscDLLibraryRetrieve(PETSC_COMM_WORLD,libs,dlib,1024,found);CHKERRQ(ierr);
54487e5849SBarry Smith     if (*found) {
55d44a1e48SBarry Smith       ierr = PetscDLLibraryAppend(PETSC_COMM_WORLD,&PetscDLLibrariesLoaded,dlib);CHKERRQ(ierr);
56487e5849SBarry Smith     }
57487e5849SBarry Smith   }
58487e5849SBarry Smith   PetscFunctionReturn(0);
59487e5849SBarry Smith }
60487e5849SBarry Smith 
613fa76a5bSLisandro Dalcin #endif
623fa76a5bSLisandro Dalcin 
63487e5849SBarry Smith #undef __FUNCT__
64e5c89e4eSSatish Balay #define __FUNCT__ "PetscInitialize_DynamicLibraries"
65e5c89e4eSSatish Balay /*
66e5c89e4eSSatish Balay     PetscInitialize_DynamicLibraries - Adds the default dynamic link libraries to the
67e5c89e4eSSatish Balay     search path.
68e5c89e4eSSatish Balay */
697087cfbeSBarry Smith PetscErrorCode  PetscInitialize_DynamicLibraries(void)
70e5c89e4eSSatish Balay {
71487e5849SBarry Smith   char           *libname[32];
72e5c89e4eSSatish Balay   PetscErrorCode ierr;
73e5c89e4eSSatish Balay   PetscInt       nmax,i;
743fa76a5bSLisandro Dalcin #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
75ace3abfcSBarry Smith   PetscBool      found;
763fa76a5bSLisandro Dalcin #endif
77e5c89e4eSSatish Balay 
7860154eb2SBarry Smith   PetscFunctionBegin;
79e5c89e4eSSatish Balay   nmax = 32;
80e5c89e4eSSatish Balay   ierr = PetscOptionsGetStringArray(PETSC_NULL,"-dll_prepend",libname,&nmax,PETSC_NULL);CHKERRQ(ierr);
81e5c89e4eSSatish Balay   for (i=0; i<nmax; i++) {
82d44a1e48SBarry Smith     ierr = PetscDLLibraryPrepend(PETSC_COMM_WORLD,&PetscDLLibrariesLoaded,libname[i]);CHKERRQ(ierr);
83e5c89e4eSSatish Balay     ierr = PetscFree(libname[i]);CHKERRQ(ierr);
84e5c89e4eSSatish Balay   }
85e5c89e4eSSatish Balay 
863fa76a5bSLisandro Dalcin #if !defined(PETSC_USE_DYNAMIC_LIBRARIES)
873fa76a5bSLisandro Dalcin   /*
883fa76a5bSLisandro Dalcin       This just initializes the most basic PETSc stuff.
893fa76a5bSLisandro Dalcin 
903fa76a5bSLisandro Dalcin     The classes, from PetscDraw to PetscTS, are initialized the first
913fa76a5bSLisandro Dalcin     time an XXCreate() is called.
923fa76a5bSLisandro Dalcin   */
9360154eb2SBarry Smith   ierr = PetscSysInitializePackage(PETSC_NULL);CHKERRQ(ierr);
943fa76a5bSLisandro Dalcin #else
9560154eb2SBarry Smith #if defined(PETSC_USE_SINGLE_LIBRARY)
96487e5849SBarry Smith   ierr = PetscLoadDynamicLibrary("",&found);CHKERRQ(ierr);
97e32f2f54SBarry Smith   if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc dynamic library \n You cannot move the dynamic libraries!");
9860154eb2SBarry Smith #else
9960154eb2SBarry Smith   ierr = PetscLoadDynamicLibrary("sys",&found);CHKERRQ(ierr);
10060154eb2SBarry Smith   if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc dynamic library \n You cannot move the dynamic libraries!");
101487e5849SBarry Smith   ierr = PetscLoadDynamicLibrary("vec",&found);CHKERRQ(ierr);
102e32f2f54SBarry Smith   if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc Vec dynamic library \n You cannot move the dynamic libraries!");
103487e5849SBarry Smith   ierr = PetscLoadDynamicLibrary("mat",&found);CHKERRQ(ierr);
104e32f2f54SBarry Smith   if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc Mat dynamic library \n You cannot move the dynamic libraries!");
105487e5849SBarry Smith   ierr = PetscLoadDynamicLibrary("dm",&found);CHKERRQ(ierr);
106e32f2f54SBarry Smith   if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc DM dynamic library \n You cannot move the dynamic libraries!");
10760154eb2SBarry Smith   ierr = PetscLoadDynamicLibrary("characteristic",&found);CHKERRQ(ierr);
10860154eb2SBarry Smith   if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc Characteristic dynamic library \n You cannot move the dynamic libraries!");
109487e5849SBarry Smith   ierr = PetscLoadDynamicLibrary("ksp",&found);CHKERRQ(ierr);
110e32f2f54SBarry Smith   if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc KSP dynamic library \n You cannot move the dynamic libraries!");
111487e5849SBarry Smith   ierr = PetscLoadDynamicLibrary("snes",&found);CHKERRQ(ierr);
112e32f2f54SBarry Smith   if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc SNES dynamic library \n You cannot move the dynamic libraries!");
113487e5849SBarry Smith   ierr = PetscLoadDynamicLibrary("ts",&found);CHKERRQ(ierr);
114e32f2f54SBarry Smith   if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc TS dynamic library \n You cannot move the dynamic libraries!");
115bb84e0fdSBarry Smith #endif
116e5c89e4eSSatish Balay 
117487e5849SBarry Smith   ierr = PetscLoadDynamicLibrary("mesh",&found);CHKERRQ(ierr);
118487e5849SBarry Smith   ierr = PetscLoadDynamicLibrary("contrib",&found);CHKERRQ(ierr);
1193fa76a5bSLisandro Dalcin #endif
120e5c89e4eSSatish Balay 
121e5c89e4eSSatish Balay   nmax = 32;
122e5c89e4eSSatish Balay   ierr = PetscOptionsGetStringArray(PETSC_NULL,"-dll_append",libname,&nmax,PETSC_NULL);CHKERRQ(ierr);
123e5c89e4eSSatish Balay   for (i=0; i<nmax; i++) {
124d44a1e48SBarry Smith     ierr = PetscDLLibraryAppend(PETSC_COMM_WORLD,&PetscDLLibrariesLoaded,libname[i]);CHKERRQ(ierr);
125e5c89e4eSSatish Balay     ierr = PetscFree(libname[i]);CHKERRQ(ierr);
126e5c89e4eSSatish Balay   }
1273fa76a5bSLisandro Dalcin 
128e5c89e4eSSatish Balay   PetscFunctionReturn(0);
129e5c89e4eSSatish Balay }
130e5c89e4eSSatish Balay 
131e5c89e4eSSatish Balay #undef __FUNCT__
132e5c89e4eSSatish Balay #define __FUNCT__ "PetscFinalize_DynamicLibraries"
133ebd79076SLisandro Dalcin /*
134ebd79076SLisandro Dalcin      PetscFinalize_DynamicLibraries - Closes the opened dynamic libraries.
135ebd79076SLisandro Dalcin */
136e5c89e4eSSatish Balay PetscErrorCode PetscFinalize_DynamicLibraries(void)
137e5c89e4eSSatish Balay {
138ebd79076SLisandro Dalcin   PetscErrorCode ierr;
139ace3abfcSBarry Smith   PetscBool      flg = PETSC_FALSE;
140e5c89e4eSSatish Balay 
141ebd79076SLisandro Dalcin   PetscFunctionBegin;
142acfcf0e5SJed Brown   ierr = PetscOptionsGetBool(PETSC_NULL,"-dll_view",&flg,PETSC_NULL);CHKERRQ(ierr);
143d44a1e48SBarry Smith   if (flg) { ierr = PetscDLLibraryPrintPath(PetscDLLibrariesLoaded);CHKERRQ(ierr); }
144d44a1e48SBarry Smith   ierr = PetscDLLibraryClose(PetscDLLibrariesLoaded);CHKERRQ(ierr);
145d44a1e48SBarry Smith   PetscDLLibrariesLoaded = 0;
146e5c89e4eSSatish Balay   PetscFunctionReturn(0);
147e5c89e4eSSatish Balay }
148e5c89e4eSSatish Balay 
149e4d1774bSDmitry Karpeev 
150e4d1774bSDmitry Karpeev 
151e5c89e4eSSatish Balay /* ------------------------------------------------------------------------------*/
1522bb46157SSatish Balay struct _n_PetscFList {
153e5c89e4eSSatish Balay   void        (*routine)(void);   /* the routine */
154e5c89e4eSSatish Balay   char        *path;              /* path of link library containing routine */
155e5c89e4eSSatish Balay   char        *name;              /* string to identify routine */
156e5c89e4eSSatish Balay   char        *rname;             /* routine name in dynamic library */
157e5c89e4eSSatish Balay   PetscFList  next;               /* next pointer */
158e5c89e4eSSatish Balay   PetscFList  next_list;          /* used to maintain list of all lists for freeing */
159e5c89e4eSSatish Balay };
160e5c89e4eSSatish Balay 
161e5c89e4eSSatish Balay /*
162e5c89e4eSSatish Balay      Keep a linked list of PetscFLists so that we can destroy all the left-over ones.
163e5c89e4eSSatish Balay */
164e5c89e4eSSatish Balay static PetscFList   dlallhead = 0;
165e5c89e4eSSatish Balay 
166e5c89e4eSSatish Balay #undef __FUNCT__
167e5c89e4eSSatish Balay #define __FUNCT__ "PetscFListAdd"
168e5c89e4eSSatish Balay /*@C
169e4d1774bSDmitry Karpeev    PetscFListAdd - Given a routine and a string id, saves that routine in the
170e5c89e4eSSatish Balay    specified registry.
171e5c89e4eSSatish Balay 
172e5c89e4eSSatish Balay      Not Collective
173e5c89e4eSSatish Balay 
174e5c89e4eSSatish Balay    Input Parameters:
175e5c89e4eSSatish Balay +  fl    - pointer registry
176e5c89e4eSSatish Balay .  name  - string to identify routine
177e5c89e4eSSatish Balay .  rname - routine name in dynamic library
178e5c89e4eSSatish Balay -  fnc   - function pointer (optional if using dynamic libraries)
179e5c89e4eSSatish Balay 
180e5c89e4eSSatish Balay    Notes:
181e5c89e4eSSatish Balay    To remove a registered routine, pass in a PETSC_NULL rname and fnc().
182e5c89e4eSSatish Balay 
183e5c89e4eSSatish Balay    Users who wish to register new classes for use by a particular PETSc
184e5c89e4eSSatish Balay    component (e.g., SNES) should generally call the registration routine
185e5c89e4eSSatish Balay    for that particular component (e.g., SNESRegisterDynamic()) instead of
186e4d1774bSDmitry Karpeev    calling PetscFListAdd() directly.
187e5c89e4eSSatish Balay 
188e5c89e4eSSatish Balay    ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR}, or ${any environmental variable}
189e5c89e4eSSatish Balay   occuring in pathname will be replaced with appropriate values.
190e5c89e4eSSatish Balay 
191e5c89e4eSSatish Balay    Level: developer
192e5c89e4eSSatish Balay 
193e5c89e4eSSatish Balay .seealso: PetscFListDestroy(), SNESRegisterDynamic(), KSPRegisterDynamic(),
194e5c89e4eSSatish Balay           PCRegisterDynamic(), TSRegisterDynamic(), PetscFList
195e5c89e4eSSatish Balay @*/
1967087cfbeSBarry Smith PetscErrorCode  PetscFListAdd(PetscFList *fl,const char name[],const char rname[],void (*fnc)(void))
197e5c89e4eSSatish Balay {
198e5c89e4eSSatish Balay   PetscFList     entry,ne;
199e5c89e4eSSatish Balay   PetscErrorCode ierr;
200e5c89e4eSSatish Balay   char           *fpath,*fname;
201e5c89e4eSSatish Balay 
202e5c89e4eSSatish Balay   PetscFunctionBegin;
203e5c89e4eSSatish Balay   if (!*fl) {
2042bb46157SSatish Balay     ierr           = PetscNew(struct _n_PetscFList,&entry);CHKERRQ(ierr);
205e5c89e4eSSatish Balay     ierr           = PetscStrallocpy(name,&entry->name);CHKERRQ(ierr);
206e5c89e4eSSatish Balay     ierr           = PetscFListGetPathAndFunction(rname,&fpath,&fname);CHKERRQ(ierr);
207e5c89e4eSSatish Balay     entry->path    = fpath;
208e5c89e4eSSatish Balay     entry->rname   = fname;
209e5c89e4eSSatish Balay     entry->routine = fnc;
210e5c89e4eSSatish Balay     entry->next    = 0;
211e5c89e4eSSatish Balay     *fl = entry;
212e5c89e4eSSatish Balay 
213e5c89e4eSSatish Balay     /* add this new list to list of all lists */
214e5c89e4eSSatish Balay     if (!dlallhead) {
215e5c89e4eSSatish Balay       dlallhead        = *fl;
216e5c89e4eSSatish Balay       (*fl)->next_list = 0;
217e5c89e4eSSatish Balay     } else {
218e5c89e4eSSatish Balay       ne               = dlallhead;
219e5c89e4eSSatish Balay       dlallhead        = *fl;
220e5c89e4eSSatish Balay       (*fl)->next_list = ne;
221e5c89e4eSSatish Balay     }
222e5c89e4eSSatish Balay   } else {
223e5c89e4eSSatish Balay     /* search list to see if it is already there */
224e5c89e4eSSatish Balay     ne = *fl;
225e5c89e4eSSatish Balay     while (ne) {
226ace3abfcSBarry Smith       PetscBool  founddup;
227e5c89e4eSSatish Balay 
228e5c89e4eSSatish Balay       ierr = PetscStrcmp(ne->name,name,&founddup);CHKERRQ(ierr);
229e5c89e4eSSatish Balay       if (founddup) { /* found duplicate */
230e5c89e4eSSatish Balay         ierr = PetscFListGetPathAndFunction(rname,&fpath,&fname);CHKERRQ(ierr);
231503cfb0cSBarry Smith         ierr = PetscFree(ne->path);CHKERRQ(ierr);
232503cfb0cSBarry Smith         ierr = PetscFree(ne->rname);CHKERRQ(ierr);
233e5c89e4eSSatish Balay         ne->path    = fpath;
234e5c89e4eSSatish Balay         ne->rname   = fname;
235e5c89e4eSSatish Balay         ne->routine = fnc;
236e5c89e4eSSatish Balay         PetscFunctionReturn(0);
237e5c89e4eSSatish Balay       }
238e5c89e4eSSatish Balay       if (ne->next) ne = ne->next; else break;
239e5c89e4eSSatish Balay     }
240e5c89e4eSSatish Balay     /* create new entry and add to end of list */
2412bb46157SSatish Balay     ierr           = PetscNew(struct _n_PetscFList,&entry);CHKERRQ(ierr);
242e5c89e4eSSatish Balay     ierr           = PetscStrallocpy(name,&entry->name);CHKERRQ(ierr);
243e5c89e4eSSatish Balay     ierr           = PetscFListGetPathAndFunction(rname,&fpath,&fname);CHKERRQ(ierr);
244e5c89e4eSSatish Balay     entry->path    = fpath;
245e5c89e4eSSatish Balay     entry->rname   = fname;
246e5c89e4eSSatish Balay     entry->routine = fnc;
247e5c89e4eSSatish Balay     entry->next    = 0;
248e5c89e4eSSatish Balay     ne->next       = entry;
249e5c89e4eSSatish Balay   }
250e5c89e4eSSatish Balay   PetscFunctionReturn(0);
251e5c89e4eSSatish Balay }
252e5c89e4eSSatish Balay 
253e5c89e4eSSatish Balay #undef __FUNCT__
254e5c89e4eSSatish Balay #define __FUNCT__ "PetscFListDestroy"
255e5c89e4eSSatish Balay /*@
256e5c89e4eSSatish Balay     PetscFListDestroy - Destroys a list of registered routines.
257e5c89e4eSSatish Balay 
258e5c89e4eSSatish Balay     Input Parameter:
259e5c89e4eSSatish Balay .   fl  - pointer to list
260e5c89e4eSSatish Balay 
261e5c89e4eSSatish Balay     Level: developer
262e5c89e4eSSatish Balay 
263e5c89e4eSSatish Balay .seealso: PetscFListAddDynamic(), PetscFList
264e5c89e4eSSatish Balay @*/
2657087cfbeSBarry Smith PetscErrorCode  PetscFListDestroy(PetscFList *fl)
266e5c89e4eSSatish Balay {
267e5c89e4eSSatish Balay   PetscFList     next,entry,tmp = dlallhead;
268e5c89e4eSSatish Balay   PetscErrorCode ierr;
269e5c89e4eSSatish Balay 
270e5c89e4eSSatish Balay   PetscFunctionBegin;
2711441b1d3SBarry Smith   if (!*fl) PetscFunctionReturn(0);
27260154eb2SBarry Smith   if (!dlallhead) PetscFunctionReturn(0);
273e5c89e4eSSatish Balay 
274e5c89e4eSSatish Balay   /*
275e5c89e4eSSatish Balay        Remove this entry from the master DL list (if it is in it)
276e5c89e4eSSatish Balay   */
2771441b1d3SBarry Smith   if (dlallhead == *fl) {
278e5c89e4eSSatish Balay     if (dlallhead->next_list) {
279e5c89e4eSSatish Balay       dlallhead = dlallhead->next_list;
280e5c89e4eSSatish Balay     } else {
281e5c89e4eSSatish Balay       dlallhead = 0;
282e5c89e4eSSatish Balay     }
283e5c89e4eSSatish Balay   } else {
2841441b1d3SBarry Smith     while (tmp->next_list != *fl) {
285e5c89e4eSSatish Balay       tmp = tmp->next_list;
286e5c89e4eSSatish Balay       if (!tmp->next_list) break;
287e5c89e4eSSatish Balay     }
288e5c89e4eSSatish Balay     if (tmp->next_list) tmp->next_list = tmp->next_list->next_list;
289e5c89e4eSSatish Balay   }
290e5c89e4eSSatish Balay 
291e5c89e4eSSatish Balay   /* free this list */
2921441b1d3SBarry Smith   entry = *fl;
293e5c89e4eSSatish Balay   while (entry) {
294e5c89e4eSSatish Balay     next = entry->next;
295503cfb0cSBarry Smith     ierr = PetscFree(entry->path);CHKERRQ(ierr);
296e5c89e4eSSatish Balay     ierr = PetscFree(entry->name);CHKERRQ(ierr);
297e5c89e4eSSatish Balay     ierr = PetscFree(entry->rname);CHKERRQ(ierr);
298e5c89e4eSSatish Balay     ierr = PetscFree(entry);CHKERRQ(ierr);
299e5c89e4eSSatish Balay     entry = next;
300e5c89e4eSSatish Balay   }
3011441b1d3SBarry Smith   *fl = 0;
302e5c89e4eSSatish Balay   PetscFunctionReturn(0);
303e5c89e4eSSatish Balay }
304e5c89e4eSSatish Balay 
305e5c89e4eSSatish Balay /*
306e5c89e4eSSatish Balay    Destroys all the function lists that anyone has every registered, such as KSPList, VecList, etc.
307e5c89e4eSSatish Balay */
308e5c89e4eSSatish Balay #undef __FUNCT__
309e5c89e4eSSatish Balay #define __FUNCT__ "PetscFListDestroyAll"
3107087cfbeSBarry Smith PetscErrorCode  PetscFListDestroyAll(void)
311e5c89e4eSSatish Balay {
312e5c89e4eSSatish Balay   PetscFList     tmp2,tmp1 = dlallhead;
313e5c89e4eSSatish Balay   PetscErrorCode ierr;
314e5c89e4eSSatish Balay 
315e5c89e4eSSatish Balay   PetscFunctionBegin;
316e5c89e4eSSatish Balay   while (tmp1) {
317e5c89e4eSSatish Balay     tmp2 = tmp1->next_list;
3181441b1d3SBarry Smith     ierr = PetscFListDestroy(&tmp1);CHKERRQ(ierr);
319e5c89e4eSSatish Balay     tmp1 = tmp2;
320e5c89e4eSSatish Balay   }
321e5c89e4eSSatish Balay   dlallhead = 0;
322e5c89e4eSSatish Balay   PetscFunctionReturn(0);
323e5c89e4eSSatish Balay }
324e5c89e4eSSatish Balay 
325e5c89e4eSSatish Balay #undef __FUNCT__
326e5c89e4eSSatish Balay #define __FUNCT__ "PetscFListFind"
327e5c89e4eSSatish Balay /*@C
328e5c89e4eSSatish Balay     PetscFListFind - Given a name, finds the matching routine.
329e5c89e4eSSatish Balay 
330e5c89e4eSSatish Balay     Input Parameters:
3311d280d73SBarry Smith +   fl   - pointer to list
3321d280d73SBarry Smith .   comm - processors looking for routine
3334b91b6eaSBarry Smith .   name - name string
3344b91b6eaSBarry Smith -   searchlibraries - if not found in the list then search the dynamic libraries and executable for the symbol
335e5c89e4eSSatish Balay 
336e5c89e4eSSatish Balay     Output Parameters:
337e5c89e4eSSatish Balay .   r - the routine
338e5c89e4eSSatish Balay 
339e5c89e4eSSatish Balay     Level: developer
340e5c89e4eSSatish Balay 
341e5c89e4eSSatish Balay .seealso: PetscFListAddDynamic(), PetscFList
342e5c89e4eSSatish Balay @*/
3434b91b6eaSBarry Smith PetscErrorCode  PetscFListFind(PetscFList fl,MPI_Comm comm,const char name[],PetscBool searchlibraries,void (**r)(void))
344e5c89e4eSSatish Balay {
345e5c89e4eSSatish Balay   PetscFList     entry = fl;
346e5c89e4eSSatish Balay   PetscErrorCode ierr;
347e5c89e4eSSatish Balay   char           *function,*path;
348ace3abfcSBarry Smith   PetscBool      flg,f1,f2,f3;
3490598bfebSBarry Smith #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
350e5c89e4eSSatish Balay   char           *newpath;
351e5c89e4eSSatish Balay #endif
352e5c89e4eSSatish Balay 
353e5c89e4eSSatish Balay   PetscFunctionBegin;
354e32f2f54SBarry Smith   if (!name) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to find routine with null name");
355e5c89e4eSSatish Balay 
356e5c89e4eSSatish Balay   *r = 0;
357e5c89e4eSSatish Balay   ierr = PetscFListGetPathAndFunction(name,&path,&function);CHKERRQ(ierr);
358e5c89e4eSSatish Balay 
359e5c89e4eSSatish Balay   /*
360e5c89e4eSSatish Balay         If path then append it to search libraries
361e5c89e4eSSatish Balay   */
3620598bfebSBarry Smith #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
363e5c89e4eSSatish Balay   if (path) {
364d44a1e48SBarry Smith     ierr = PetscDLLibraryAppend(comm,&PetscDLLibrariesLoaded,path);CHKERRQ(ierr);
365e5c89e4eSSatish Balay   }
366e5c89e4eSSatish Balay #endif
367e5c89e4eSSatish Balay 
368e5c89e4eSSatish Balay   while (entry) {
369e5c89e4eSSatish Balay     flg = PETSC_FALSE;
370e5c89e4eSSatish Balay     if (path && entry->path) {
371e5c89e4eSSatish Balay       ierr = PetscStrcmp(path,entry->path,&f1);CHKERRQ(ierr);
372e5c89e4eSSatish Balay       ierr = PetscStrcmp(function,entry->rname,&f2);CHKERRQ(ierr);
373e5c89e4eSSatish Balay       ierr = PetscStrcmp(function,entry->name,&f3);CHKERRQ(ierr);
374ace3abfcSBarry Smith       flg =  (PetscBool) ((f1 && f2) || (f1 && f3));
375e5c89e4eSSatish Balay     } else if (!path) {
376e5c89e4eSSatish Balay       ierr = PetscStrcmp(function,entry->name,&f1);CHKERRQ(ierr);
377e5c89e4eSSatish Balay       ierr = PetscStrcmp(function,entry->rname,&f2);CHKERRQ(ierr);
378ace3abfcSBarry Smith       flg =  (PetscBool) (f1 || f2);
379e5c89e4eSSatish Balay     } else {
380e5c89e4eSSatish Balay       ierr = PetscStrcmp(function,entry->name,&flg);CHKERRQ(ierr);
381e5c89e4eSSatish Balay       if (flg) {
382e5c89e4eSSatish Balay         ierr = PetscFree(function);CHKERRQ(ierr);
383e5c89e4eSSatish Balay         ierr = PetscStrallocpy(entry->rname,&function);CHKERRQ(ierr);
384e5c89e4eSSatish Balay       } else {
385e5c89e4eSSatish Balay         ierr = PetscStrcmp(function,entry->rname,&flg);CHKERRQ(ierr);
386e5c89e4eSSatish Balay       }
387e5c89e4eSSatish Balay     }
388e5c89e4eSSatish Balay 
389e5c89e4eSSatish Balay     if (flg) {
390e5c89e4eSSatish Balay       if (entry->routine) {
391e5c89e4eSSatish Balay         *r   = entry->routine;
392503cfb0cSBarry Smith         ierr = PetscFree(path);CHKERRQ(ierr);
393e5c89e4eSSatish Balay         ierr = PetscFree(function);CHKERRQ(ierr);
394e5c89e4eSSatish Balay         PetscFunctionReturn(0);
395e5c89e4eSSatish Balay       }
3965629bde7SJed Brown       if (!(entry->rname && entry->rname[0])) { /* The entry has been cleared */
3975629bde7SJed Brown         ierr = PetscFree(function);CHKERRQ(ierr);
3985629bde7SJed Brown         PetscFunctionReturn(0);
3995629bde7SJed Brown       }
400e5c89e4eSSatish Balay       if ((path && entry->path && f3) || (!path && f1)) { /* convert name of function (alias) to actual function name */
401e5c89e4eSSatish Balay         ierr = PetscFree(function);CHKERRQ(ierr);
402e5c89e4eSSatish Balay         ierr = PetscStrallocpy(entry->rname,&function);CHKERRQ(ierr);
403e5c89e4eSSatish Balay       }
404e5c89e4eSSatish Balay 
405e5c89e4eSSatish Balay       /* it is not yet in memory so load from dynamic library */
4060598bfebSBarry Smith #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
407e5c89e4eSSatish Balay       newpath = path;
408e5c89e4eSSatish Balay       if (!path) newpath = entry->path;
409d44a1e48SBarry Smith       ierr = PetscDLLibrarySym(comm,&PetscDLLibrariesLoaded,newpath,entry->rname,(void **)r);CHKERRQ(ierr);
410e5c89e4eSSatish Balay       if (*r) {
411e5c89e4eSSatish Balay         entry->routine = *r;
412503cfb0cSBarry Smith         ierr = PetscFree(path);CHKERRQ(ierr);
413e5c89e4eSSatish Balay         ierr = PetscFree(function);CHKERRQ(ierr);
414e5c89e4eSSatish Balay         PetscFunctionReturn(0);
415e5c89e4eSSatish Balay       }
416e5c89e4eSSatish Balay #endif
417e5c89e4eSSatish Balay     }
418e5c89e4eSSatish Balay     entry = entry->next;
419e5c89e4eSSatish Balay   }
420e5c89e4eSSatish Balay 
4210598bfebSBarry Smith #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
4224b91b6eaSBarry Smith   if (searchlibraries) {
423e5c89e4eSSatish Balay     /* Function never registered; try for it anyway */
424d44a1e48SBarry Smith     ierr = PetscDLLibrarySym(comm,&PetscDLLibrariesLoaded,path,function,(void **)r);CHKERRQ(ierr);
425503cfb0cSBarry Smith     ierr = PetscFree(path);CHKERRQ(ierr);
426e5c89e4eSSatish Balay     if (*r) {
427e5c89e4eSSatish Balay       ierr = PetscFListAdd(&fl,name,name,*r);CHKERRQ(ierr);
428e5c89e4eSSatish Balay     }
4294b91b6eaSBarry Smith   }
430e5c89e4eSSatish Balay #endif
431e5c89e4eSSatish Balay   ierr = PetscFree(function);CHKERRQ(ierr);
432e5c89e4eSSatish Balay   PetscFunctionReturn(0);
433e5c89e4eSSatish Balay }
434e5c89e4eSSatish Balay 
435e5c89e4eSSatish Balay #undef __FUNCT__
436e5c89e4eSSatish Balay #define __FUNCT__ "PetscFListView"
437e5c89e4eSSatish Balay /*@
438e5c89e4eSSatish Balay    PetscFListView - prints out contents of an PetscFList
439e5c89e4eSSatish Balay 
440e5c89e4eSSatish Balay    Collective over MPI_Comm
441e5c89e4eSSatish Balay 
442e5c89e4eSSatish Balay    Input Parameters:
443e5c89e4eSSatish Balay +  list - the list of functions
444e5c89e4eSSatish Balay -  viewer - currently ignored
445e5c89e4eSSatish Balay 
446e5c89e4eSSatish Balay    Level: developer
447e5c89e4eSSatish Balay 
448e5c89e4eSSatish Balay .seealso: PetscFListAddDynamic(), PetscFListPrintTypes(), PetscFList
449e5c89e4eSSatish Balay @*/
4507087cfbeSBarry Smith PetscErrorCode  PetscFListView(PetscFList list,PetscViewer viewer)
451e5c89e4eSSatish Balay {
452e5c89e4eSSatish Balay   PetscErrorCode ierr;
453ace3abfcSBarry Smith   PetscBool      iascii;
454e5c89e4eSSatish Balay 
455e5c89e4eSSatish Balay   PetscFunctionBegin;
456e5c89e4eSSatish Balay   if (!viewer) viewer = PETSC_VIEWER_STDOUT_SELF;
457e5c89e4eSSatish Balay   PetscValidPointer(list,1);
4580700a824SBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2);
459e5c89e4eSSatish Balay 
460251f4c67SDmitry Karpeev   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
461e32f2f54SBarry Smith   if (!iascii) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Only ASCII viewer supported");
462e5c89e4eSSatish Balay 
463e5c89e4eSSatish Balay   while (list) {
464e5c89e4eSSatish Balay     if (list->path) {
465e5c89e4eSSatish Balay       ierr = PetscViewerASCIIPrintf(viewer," %s %s %s\n",list->path,list->name,list->rname);CHKERRQ(ierr);
466e5c89e4eSSatish Balay     } else {
467e5c89e4eSSatish Balay       ierr = PetscViewerASCIIPrintf(viewer," %s %s\n",list->name,list->rname);CHKERRQ(ierr);
468e5c89e4eSSatish Balay     }
469e5c89e4eSSatish Balay     list = list->next;
470e5c89e4eSSatish Balay   }
471e5c89e4eSSatish Balay   ierr = PetscViewerASCIIPrintf(viewer,"\n");CHKERRQ(ierr);
472e5c89e4eSSatish Balay   PetscFunctionReturn(0);
473e5c89e4eSSatish Balay }
474e5c89e4eSSatish Balay 
475e5c89e4eSSatish Balay #undef __FUNCT__
476e5c89e4eSSatish Balay #define __FUNCT__ "PetscFListGet"
477e5c89e4eSSatish Balay /*@
478e5c89e4eSSatish Balay    PetscFListGet - Gets an array the contains the entries in PetscFList, this is used
479e5c89e4eSSatish Balay          by help etc.
480e5c89e4eSSatish Balay 
481e5c89e4eSSatish Balay    Collective over MPI_Comm
482e5c89e4eSSatish Balay 
483e5c89e4eSSatish Balay    Input Parameter:
484e5c89e4eSSatish Balay .  list   - list of types
485e5c89e4eSSatish Balay 
486e5c89e4eSSatish Balay    Output Parameter:
487e5c89e4eSSatish Balay +  array - array of names
488e5c89e4eSSatish Balay -  n - length of array
489e5c89e4eSSatish Balay 
490e5c89e4eSSatish Balay    Notes:
491e5c89e4eSSatish Balay        This allocates the array so that must be freed. BUT the individual entries are
492e5c89e4eSSatish Balay     not copied so should not be freed.
493e5c89e4eSSatish Balay 
494e5c89e4eSSatish Balay    Level: developer
495e5c89e4eSSatish Balay 
496e5c89e4eSSatish Balay .seealso: PetscFListAddDynamic(), PetscFList
497e5c89e4eSSatish Balay @*/
4987087cfbeSBarry Smith PetscErrorCode  PetscFListGet(PetscFList list,char ***array,int *n)
499e5c89e4eSSatish Balay {
500e5c89e4eSSatish Balay   PetscErrorCode ierr;
501e5c89e4eSSatish Balay   PetscInt       count = 0;
502e5c89e4eSSatish Balay   PetscFList     klist = list;
503e5c89e4eSSatish Balay 
504e5c89e4eSSatish Balay   PetscFunctionBegin;
505e5c89e4eSSatish Balay   while (list) {
506e5c89e4eSSatish Balay     list = list->next;
507e5c89e4eSSatish Balay     count++;
508e5c89e4eSSatish Balay   }
509e5c89e4eSSatish Balay   ierr  = PetscMalloc((count+1)*sizeof(char *),array);CHKERRQ(ierr);
510e5c89e4eSSatish Balay   count = 0;
511e5c89e4eSSatish Balay   while (klist) {
512e5c89e4eSSatish Balay     (*array)[count] = klist->name;
513e5c89e4eSSatish Balay     klist = klist->next;
514e5c89e4eSSatish Balay     count++;
515e5c89e4eSSatish Balay   }
516e5c89e4eSSatish Balay   (*array)[count] = 0;
517e5c89e4eSSatish Balay   *n = count+1;
518e5c89e4eSSatish Balay   PetscFunctionReturn(0);
519e5c89e4eSSatish Balay }
520e5c89e4eSSatish Balay 
521e5c89e4eSSatish Balay 
522e5c89e4eSSatish Balay #undef __FUNCT__
523e5c89e4eSSatish Balay #define __FUNCT__ "PetscFListPrintTypes"
524e5c89e4eSSatish Balay /*@C
525e5c89e4eSSatish Balay    PetscFListPrintTypes - Prints the methods available.
526e5c89e4eSSatish Balay 
527e5c89e4eSSatish Balay    Collective over MPI_Comm
528e5c89e4eSSatish Balay 
529e5c89e4eSSatish Balay    Input Parameters:
530e5c89e4eSSatish Balay +  comm   - the communicator (usually MPI_COMM_WORLD)
531e5c89e4eSSatish Balay .  fd     - file to print to, usually stdout
532e5c89e4eSSatish Balay .  prefix - prefix to prepend to name (optional)
533e5c89e4eSSatish Balay .  name   - option string (for example, "-ksp_type")
534e5c89e4eSSatish Balay .  text - short description of the object (for example, "Krylov solvers")
535e5c89e4eSSatish Balay .  man - name of manual page that discusses the object (for example, "KSPCreate")
5363cc1e11dSBarry Smith .  list   - list of types
5373cc1e11dSBarry Smith -  def - default (current) value
538e5c89e4eSSatish Balay 
539e5c89e4eSSatish Balay    Level: developer
540e5c89e4eSSatish Balay 
541e5c89e4eSSatish Balay .seealso: PetscFListAddDynamic(), PetscFList
542e5c89e4eSSatish Balay @*/
5437087cfbeSBarry Smith PetscErrorCode  PetscFListPrintTypes(MPI_Comm comm,FILE *fd,const char prefix[],const char name[],const char text[],const char man[],PetscFList list,const char def[])
544e5c89e4eSSatish Balay {
545e5c89e4eSSatish Balay   PetscErrorCode ierr;
546e5c89e4eSSatish Balay   PetscInt       count = 0;
547e5c89e4eSSatish Balay   char           p[64];
548e5c89e4eSSatish Balay 
549e5c89e4eSSatish Balay   PetscFunctionBegin;
550da9f1d6bSBarry Smith   if (!fd) fd = PETSC_STDOUT;
551e5c89e4eSSatish Balay 
552e5c89e4eSSatish Balay   ierr = PetscStrcpy(p,"-");CHKERRQ(ierr);
553e5c89e4eSSatish Balay   if (prefix) {ierr = PetscStrcat(p,prefix);CHKERRQ(ierr);}
5543cc1e11dSBarry Smith   ierr = PetscFPrintf(comm,fd,"  %s%s <%s>: %s (one of)",p,name+1,def,text);CHKERRQ(ierr);
555e5c89e4eSSatish Balay 
556e5c89e4eSSatish Balay   while (list) {
557e5c89e4eSSatish Balay     ierr = PetscFPrintf(comm,fd," %s",list->name);CHKERRQ(ierr);
558e5c89e4eSSatish Balay     list = list->next;
559e5c89e4eSSatish Balay     count++;
560e5c89e4eSSatish Balay     if (count == 8) {ierr = PetscFPrintf(comm,fd,"\n     ");CHKERRQ(ierr);}
561e5c89e4eSSatish Balay   }
562e5c89e4eSSatish Balay   ierr = PetscFPrintf(comm,fd," (%s)\n",man);CHKERRQ(ierr);
563e5c89e4eSSatish Balay   PetscFunctionReturn(0);
564e5c89e4eSSatish Balay }
565e5c89e4eSSatish Balay 
566e5c89e4eSSatish Balay #undef __FUNCT__
567e5c89e4eSSatish Balay #define __FUNCT__ "PetscFListDuplicate"
568e5c89e4eSSatish Balay /*@
569e5c89e4eSSatish Balay     PetscFListDuplicate - Creates a new list from a given object list.
570e5c89e4eSSatish Balay 
571e5c89e4eSSatish Balay     Input Parameters:
572e5c89e4eSSatish Balay .   fl   - pointer to list
573e5c89e4eSSatish Balay 
574e5c89e4eSSatish Balay     Output Parameters:
575e5c89e4eSSatish Balay .   nl - the new list (should point to 0 to start, otherwise appends)
576e5c89e4eSSatish Balay 
577e5c89e4eSSatish Balay     Level: developer
578e5c89e4eSSatish Balay 
579e5c89e4eSSatish Balay .seealso: PetscFList, PetscFListAdd(), PetscFlistDestroy()
580e5c89e4eSSatish Balay 
581e5c89e4eSSatish Balay @*/
5827087cfbeSBarry Smith PetscErrorCode  PetscFListDuplicate(PetscFList fl,PetscFList *nl)
583e5c89e4eSSatish Balay {
584e5c89e4eSSatish Balay   PetscErrorCode ierr;
585e5c89e4eSSatish Balay   char           path[PETSC_MAX_PATH_LEN];
586e5c89e4eSSatish Balay 
587e5c89e4eSSatish Balay   PetscFunctionBegin;
588e5c89e4eSSatish Balay   while (fl) {
589e5c89e4eSSatish Balay     /* this is silly, rebuild the complete pathname */
590e5c89e4eSSatish Balay     if (fl->path) {
591e5c89e4eSSatish Balay       ierr = PetscStrcpy(path,fl->path);CHKERRQ(ierr);
592e5c89e4eSSatish Balay       ierr = PetscStrcat(path,":");CHKERRQ(ierr);
593e5c89e4eSSatish Balay       ierr = PetscStrcat(path,fl->name);CHKERRQ(ierr);
594e5c89e4eSSatish Balay     } else {
595e5c89e4eSSatish Balay       ierr = PetscStrcpy(path,fl->name);CHKERRQ(ierr);
596e5c89e4eSSatish Balay     }
597e5c89e4eSSatish Balay     ierr = PetscFListAdd(nl,path,fl->rname,fl->routine);CHKERRQ(ierr);
598e5c89e4eSSatish Balay     fl   = fl->next;
599e5c89e4eSSatish Balay   }
600e5c89e4eSSatish Balay   PetscFunctionReturn(0);
601e5c89e4eSSatish Balay }
602e5c89e4eSSatish Balay 
603e5c89e4eSSatish Balay 
604e5c89e4eSSatish Balay #undef __FUNCT__
605e5c89e4eSSatish Balay #define __FUNCT__ "PetscFListConcat"
606e5c89e4eSSatish Balay /*
607e5c89e4eSSatish Balay     PetscFListConcat - joins name of a libary, and the path where it is located
608e5c89e4eSSatish Balay     into a single string.
609e5c89e4eSSatish Balay 
610e5c89e4eSSatish Balay     Input Parameters:
611e5c89e4eSSatish Balay .   path   - path to the library name.
612e5c89e4eSSatish Balay .   name   - name of the library
613e5c89e4eSSatish Balay 
614e5c89e4eSSatish Balay     Output Parameters:
615e5c89e4eSSatish Balay .   fullname - the name that is the union of the path and the library name,
616e5c89e4eSSatish Balay                delimited by a semicolon, i.e., path:name
617e5c89e4eSSatish Balay 
618e5c89e4eSSatish Balay     Notes:
619e5c89e4eSSatish Balay     If the path is NULL, assumes that the name, specified also includes
620e5c89e4eSSatish Balay     the path as path:name
621e5c89e4eSSatish Balay 
622e5c89e4eSSatish Balay */
6237087cfbeSBarry Smith PetscErrorCode  PetscFListConcat(const char path[],const char name[],char fullname[])
624e5c89e4eSSatish Balay {
625e5c89e4eSSatish Balay   PetscErrorCode ierr;
626e5c89e4eSSatish Balay   PetscFunctionBegin;
627e5c89e4eSSatish Balay   if (path) {
628e5c89e4eSSatish Balay     ierr = PetscStrcpy(fullname,path);CHKERRQ(ierr);
629e5c89e4eSSatish Balay     ierr = PetscStrcat(fullname,":");CHKERRQ(ierr);
630e5c89e4eSSatish Balay     ierr = PetscStrcat(fullname,name);CHKERRQ(ierr);
631e5c89e4eSSatish Balay   } else {
632e5c89e4eSSatish Balay     ierr = PetscStrcpy(fullname,name);CHKERRQ(ierr);
633e5c89e4eSSatish Balay   }
634e5c89e4eSSatish Balay   PetscFunctionReturn(0);
635e5c89e4eSSatish Balay }
636e4d1774bSDmitry Karpeev 
637e4d1774bSDmitry Karpeev 
638e4d1774bSDmitry Karpeev 
639e4d1774bSDmitry Karpeev /* ------------------------------------------------------------------------------*/
640e4d1774bSDmitry Karpeev struct _n_PetscOpFList {
641e4d1774bSDmitry Karpeev   char                 *op;                /* op name */
642e4d1774bSDmitry Karpeev   PetscInt             numArgs;            /* number of arguments to the operation */
643e4d1774bSDmitry Karpeev   char                 **argTypes;         /* list of argument types */
6442356f84bSDmitry Karpeev   PetscVoidFunction    routine;            /* the routine */
645e4d1774bSDmitry Karpeev   char                 *url;               /* url naming the link library and the routine */
646e4d1774bSDmitry Karpeev   char                 *path;              /* path of link library containing routine */
647e4d1774bSDmitry Karpeev   char                 *name;              /* routine name in dynamic library */
648e4d1774bSDmitry Karpeev   PetscOpFList         next;              /* next pointer */
649e4d1774bSDmitry Karpeev   PetscOpFList         next_list;         /* used to maintain list of all lists for freeing */
650e4d1774bSDmitry Karpeev };
651e4d1774bSDmitry Karpeev 
652e4d1774bSDmitry Karpeev /*
653e4d1774bSDmitry Karpeev      Keep a linked list of PetscOfFLists so that we can destroy all the left-over ones.
654e4d1774bSDmitry Karpeev */
655e4d1774bSDmitry Karpeev static PetscOpFList   opallhead = 0;
656e4d1774bSDmitry Karpeev 
657e4d1774bSDmitry Karpeev #undef __FUNCT__
658f64744f7SDmitry Karpeev #define __FUNCT__ "PetscOpFListAdd"
659e4d1774bSDmitry Karpeev /*@C
660f64744f7SDmitry Karpeev    PetscOpFListAdd - Given a routine and a string id, saves that routine in the
661e4d1774bSDmitry Karpeev    specified registry.
662e4d1774bSDmitry Karpeev 
66348703020SDmitry Karpeev    Formally collective on comm.
664e4d1774bSDmitry Karpeev 
665e4d1774bSDmitry Karpeev    Input Parameters:
666e4d1774bSDmitry Karpeev +  comm     - processors adding the op
667e4d1774bSDmitry Karpeev .  fl       - list of known ops
668e4d1774bSDmitry Karpeev .  url      - routine locator  (optional, if not using dynamic libraries and a nonempty fnc)
669e4d1774bSDmitry Karpeev .  fnc      - function pointer (optional, if using dynamic libraries and a nonempty url)
670e4d1774bSDmitry Karpeev .  op       - operation name
671e4d1774bSDmitry Karpeev .  numArgs  - number of op arguments
67248703020SDmitry Karpeev -  argTypes - list of argument type names (const char*)
673e4d1774bSDmitry Karpeev 
674e4d1774bSDmitry Karpeev    Notes:
675e4d1774bSDmitry Karpeev    To remove a registered routine, pass in a PETSC_NULL url and fnc().
676e4d1774bSDmitry Karpeev 
677e4d1774bSDmitry Karpeev    url can be of the form  [/path/libname[.so.1.0]:]functionname[()]  where items in [] denote optional
678e4d1774bSDmitry Karpeev 
679e4d1774bSDmitry Karpeev    ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR}, or ${any environment variable}
680e4d1774bSDmitry Karpeev    occuring in url will be replaced with appropriate values.
681e4d1774bSDmitry Karpeev 
682e4d1774bSDmitry Karpeev    Level: developer
683e4d1774bSDmitry Karpeev 
684e4d1774bSDmitry Karpeev .seealso: PetscOpFListDestroy(),PetscOpFList,  PetscFListAdd(), PetscFList
685e4d1774bSDmitry Karpeev @*/
6862356f84bSDmitry Karpeev PetscErrorCode  PetscOpFListAdd(MPI_Comm comm, PetscOpFList *fl,const char url[],PetscVoidFunction fnc,const char op[], PetscInt numArgs, char* argTypes[])
687e4d1774bSDmitry Karpeev {
688e4d1774bSDmitry Karpeev   PetscOpFList   entry,e,ne;
689e4d1774bSDmitry Karpeev   PetscErrorCode ierr;
690e4d1774bSDmitry Karpeev   char           *fpath,*fname;
691e4d1774bSDmitry Karpeev   PetscInt       i;
692e4d1774bSDmitry Karpeev 
693e4d1774bSDmitry Karpeev   PetscFunctionBegin;
694e4d1774bSDmitry Karpeev   if (!*fl) {
695e4d1774bSDmitry Karpeev     ierr           = PetscNew(struct _n_PetscOpFList,&entry); CHKERRQ(ierr);
696e4d1774bSDmitry Karpeev     ierr           = PetscStrallocpy(op,&entry->op);          CHKERRQ(ierr);
697e4d1774bSDmitry Karpeev     ierr           = PetscStrallocpy(url,&(entry->url));      CHKERRQ(ierr);
698e4d1774bSDmitry Karpeev     ierr           = PetscFListGetPathAndFunction(url,&fpath,&fname);CHKERRQ(ierr);
699e4d1774bSDmitry Karpeev     entry->path    = fpath;
700e4d1774bSDmitry Karpeev     entry->name    = fname;
701e4d1774bSDmitry Karpeev     entry->routine = fnc;
70248703020SDmitry Karpeev     entry->numArgs = numArgs;
70348703020SDmitry Karpeev     if(numArgs) {
70448703020SDmitry Karpeev       ierr = PetscMalloc(sizeof(char*)*numArgs, &(entry->argTypes));    CHKERRQ(ierr);
70548703020SDmitry Karpeev       for(i = 0; i < numArgs; ++i) {
70648703020SDmitry Karpeev         ierr = PetscStrallocpy(argTypes[i], &(entry->argTypes[i]));         CHKERRQ(ierr);
70748703020SDmitry Karpeev       }
70848703020SDmitry Karpeev     }
709e4d1774bSDmitry Karpeev     entry->next    = 0;
710e4d1774bSDmitry Karpeev     *fl = entry;
711e4d1774bSDmitry Karpeev 
712e4d1774bSDmitry Karpeev     /* add this new list to list of all lists */
713e4d1774bSDmitry Karpeev     if (!opallhead) {
714e4d1774bSDmitry Karpeev       opallhead       = *fl;
715e4d1774bSDmitry Karpeev       (*fl)->next_list = 0;
716e4d1774bSDmitry Karpeev     } else {
717e4d1774bSDmitry Karpeev       ne               = opallhead;
718e4d1774bSDmitry Karpeev       opallhead        = *fl;
719e4d1774bSDmitry Karpeev       (*fl)->next_list = ne;
720e4d1774bSDmitry Karpeev     }
721e4d1774bSDmitry Karpeev   } else {
722e4d1774bSDmitry Karpeev     /* search list to see if it is already there */
723e4d1774bSDmitry Karpeev     e  = PETSC_NULL;
724e4d1774bSDmitry Karpeev     ne = *fl;
725e4d1774bSDmitry Karpeev     while (ne) {
726e4d1774bSDmitry Karpeev       PetscBool  match;
727e4d1774bSDmitry Karpeev       ierr = PetscStrcmp(ne->op,op,&match);CHKERRQ(ierr);
728e4d1774bSDmitry Karpeev       if(!match) goto next;
729e4d1774bSDmitry Karpeev       if(numArgs == ne->numArgs)
730e4d1774bSDmitry Karpeev         match = PETSC_TRUE;
731e4d1774bSDmitry Karpeev       else
732e4d1774bSDmitry Karpeev         match = PETSC_FALSE;
733e4d1774bSDmitry Karpeev       if(!match) goto next;
734e4d1774bSDmitry Karpeev       if(numArgs) {
735e4d1774bSDmitry Karpeev         for(i = 0; i < numArgs; ++i) {
736f3b60a6eSDmitry Karpeev           ierr = PetscStrcmp(argTypes[i], ne->argTypes[i], &match);  CHKERRQ(ierr);
73748703020SDmitry Karpeev           if(!match) goto next;
738e4d1774bSDmitry Karpeev         }
739e4d1774bSDmitry Karpeev       }
740e4d1774bSDmitry Karpeev       if(!url && !fnc) {
741e4d1774bSDmitry Karpeev         /* remove this record */
742e4d1774bSDmitry Karpeev         if(e) e->next = ne->next;
743e4d1774bSDmitry Karpeev         ierr = PetscFree(ne->op);    CHKERRQ(ierr);
744e4d1774bSDmitry Karpeev         ierr = PetscFree(ne->url);   CHKERRQ(ierr);
745e4d1774bSDmitry Karpeev         ierr = PetscFree(ne->path);  CHKERRQ(ierr);
746e4d1774bSDmitry Karpeev         ierr = PetscFree(ne->name);  CHKERRQ(ierr);
747e4d1774bSDmitry Karpeev         if(numArgs) {
748e4d1774bSDmitry Karpeev           for(i = 0; i < numArgs; ++i) {
749e4d1774bSDmitry Karpeev             ierr = PetscFree(ne->argTypes[i]);  CHKERRQ(ierr);
750e4d1774bSDmitry Karpeev           }
751e4d1774bSDmitry Karpeev           ierr = PetscFree(ne->argTypes);       CHKERRQ(ierr);
752e4d1774bSDmitry Karpeev         }
753e4d1774bSDmitry Karpeev         ierr = PetscFree(ne);                   CHKERRQ(ierr);
754e4d1774bSDmitry Karpeev       }
755e4d1774bSDmitry Karpeev       else {
756e4d1774bSDmitry Karpeev         /* Replace url, fpath, fname and fnc. */
757e4d1774bSDmitry Karpeev         ierr = PetscStrallocpy(url, &(ne->url)); CHKERRQ(ierr);
758e4d1774bSDmitry Karpeev         ierr = PetscFListGetPathAndFunction(url,&fpath,&fname);CHKERRQ(ierr);
759e4d1774bSDmitry Karpeev         ierr = PetscFree(ne->path);CHKERRQ(ierr);
760e4d1774bSDmitry Karpeev         ierr = PetscFree(ne->name);CHKERRQ(ierr);
761e4d1774bSDmitry Karpeev         ne->path    = fpath;
762e4d1774bSDmitry Karpeev         ne->name    = fname;
763e4d1774bSDmitry Karpeev         ne->routine = fnc;
764e4d1774bSDmitry Karpeev       }
765e4d1774bSDmitry Karpeev       PetscFunctionReturn(0);
766e4d1774bSDmitry Karpeev       next: {e = ne; ne = ne->next;}
767e4d1774bSDmitry Karpeev     }
768e4d1774bSDmitry Karpeev     /* create new entry and add to end of list */
769e4d1774bSDmitry Karpeev     ierr           = PetscNew(struct _n_PetscOpFList,&entry);           CHKERRQ(ierr);
770e4d1774bSDmitry Karpeev     ierr           = PetscStrallocpy(op,&entry->op);                    CHKERRQ(ierr);
771e4d1774bSDmitry Karpeev     entry->numArgs = numArgs;
772e4d1774bSDmitry Karpeev     if(numArgs) {
773e4d1774bSDmitry Karpeev       ierr = PetscMalloc(sizeof(char*)*numArgs, &(entry->argTypes));    CHKERRQ(ierr);
774e4d1774bSDmitry Karpeev       for(i = 0; i < numArgs; ++i) {
77548703020SDmitry Karpeev         ierr = PetscStrallocpy(argTypes[i], &(entry->argTypes[i]));         CHKERRQ(ierr);
776e4d1774bSDmitry Karpeev       }
777e4d1774bSDmitry Karpeev     }
778e4d1774bSDmitry Karpeev     ierr = PetscStrallocpy(url, &(entry->url));                         CHKERRQ(ierr);
779e4d1774bSDmitry Karpeev     ierr           = PetscFListGetPathAndFunction(url,&fpath,&fname);   CHKERRQ(ierr);
780e4d1774bSDmitry Karpeev     entry->path    = fpath;
781e4d1774bSDmitry Karpeev     entry->name    = fname;
782e4d1774bSDmitry Karpeev     entry->routine = fnc;
783e4d1774bSDmitry Karpeev     entry->next    = 0;
784e4d1774bSDmitry Karpeev     ne->next       = entry;
785e4d1774bSDmitry Karpeev   }
786e4d1774bSDmitry Karpeev   PetscFunctionReturn(0);
787e4d1774bSDmitry Karpeev }
788e4d1774bSDmitry Karpeev 
789e4d1774bSDmitry Karpeev #undef __FUNCT__
790e4d1774bSDmitry Karpeev #define __FUNCT__ "PetscOpFListDestroy"
791e4d1774bSDmitry Karpeev /*@C
792e4d1774bSDmitry Karpeev     PetscOpFListDestroy - Destroys a list of registered op routines.
793e4d1774bSDmitry Karpeev 
794e4d1774bSDmitry Karpeev     Input Parameter:
795e4d1774bSDmitry Karpeev .   fl  - pointer to list
796e4d1774bSDmitry Karpeev 
797e4d1774bSDmitry Karpeev     Level: developer
798e4d1774bSDmitry Karpeev 
799e4d1774bSDmitry Karpeev .seealso: PetscOpFListAdd(), PetscOpFList
800e4d1774bSDmitry Karpeev @*/
801e4d1774bSDmitry Karpeev PetscErrorCode  PetscOpFListDestroy(PetscOpFList *fl)
802e4d1774bSDmitry Karpeev {
803e4d1774bSDmitry Karpeev   PetscOpFList     next,entry,tmp;
804e4d1774bSDmitry Karpeev   PetscErrorCode   ierr;
805e4d1774bSDmitry Karpeev   PetscInt         i;
806e4d1774bSDmitry Karpeev 
807e4d1774bSDmitry Karpeev   PetscFunctionBegin;
808e4d1774bSDmitry Karpeev   if (!*fl) PetscFunctionReturn(0);
809e4d1774bSDmitry Karpeev   if (!opallhead) PetscFunctionReturn(0);
810e4d1774bSDmitry Karpeev 
811e4d1774bSDmitry Karpeev   /*
812e4d1774bSDmitry Karpeev        Remove this entry from the master Op list (if it is in it)
813e4d1774bSDmitry Karpeev   */
814e4d1774bSDmitry Karpeev   if (opallhead == *fl) {
815e4d1774bSDmitry Karpeev     if (opallhead->next_list) {
816e4d1774bSDmitry Karpeev       opallhead = opallhead->next_list;
817e4d1774bSDmitry Karpeev     } else {
818e4d1774bSDmitry Karpeev       opallhead = 0;
819e4d1774bSDmitry Karpeev     }
820e4d1774bSDmitry Karpeev   } else {
821e4d1774bSDmitry Karpeev     tmp = opallhead;
822e4d1774bSDmitry Karpeev     while (tmp->next_list != *fl) {
823e4d1774bSDmitry Karpeev       tmp = tmp->next_list;
824e4d1774bSDmitry Karpeev       if (!tmp->next_list) break;
825e4d1774bSDmitry Karpeev     }
826e4d1774bSDmitry Karpeev     if (tmp->next_list) tmp->next_list = tmp->next_list->next_list;
827e4d1774bSDmitry Karpeev   }
828e4d1774bSDmitry Karpeev 
829e4d1774bSDmitry Karpeev   /* free this list */
830e4d1774bSDmitry Karpeev   entry = *fl;
831e4d1774bSDmitry Karpeev   while (entry) {
832e4d1774bSDmitry Karpeev     next = entry->next;
833e4d1774bSDmitry Karpeev     ierr = PetscFree(entry->op);  CHKERRQ(ierr);
834e4d1774bSDmitry Karpeev     for(i = 0; i < entry->numArgs; ++i) {
835e4d1774bSDmitry Karpeev       ierr = PetscFree(entry->argTypes[i]); CHKERRQ(ierr);
836e4d1774bSDmitry Karpeev     }
837e4d1774bSDmitry Karpeev     ierr = PetscFree(entry->argTypes);  CHKERRQ(ierr);
838e4d1774bSDmitry Karpeev     ierr = PetscFree(entry->url);CHKERRQ(ierr);
839e4d1774bSDmitry Karpeev     ierr = PetscFree(entry->path);CHKERRQ(ierr);
840e4d1774bSDmitry Karpeev     ierr = PetscFree(entry->name);CHKERRQ(ierr);
841e4d1774bSDmitry Karpeev     ierr = PetscFree(entry);CHKERRQ(ierr);
842e4d1774bSDmitry Karpeev     entry = next;
843e4d1774bSDmitry Karpeev   }
844e4d1774bSDmitry Karpeev   *fl = 0;
845e4d1774bSDmitry Karpeev   PetscFunctionReturn(0);
846e4d1774bSDmitry Karpeev }
847e4d1774bSDmitry Karpeev 
848e4d1774bSDmitry Karpeev /*
849e4d1774bSDmitry Karpeev    Destroys all the function lists that anyone has every registered, such as MatOpList, etc.
850e4d1774bSDmitry Karpeev */
851e4d1774bSDmitry Karpeev #undef __FUNCT__
852e4d1774bSDmitry Karpeev #define __FUNCT__ "PetscOpFListDestroyAll"
853e4d1774bSDmitry Karpeev PetscErrorCode  PetscOpFListDestroyAll(void)
854e4d1774bSDmitry Karpeev {
855e4d1774bSDmitry Karpeev   PetscOpFList     tmp2,tmp1 = opallhead;
856e4d1774bSDmitry Karpeev   PetscErrorCode ierr;
857e4d1774bSDmitry Karpeev 
858e4d1774bSDmitry Karpeev   PetscFunctionBegin;
859e4d1774bSDmitry Karpeev   while (tmp1) {
860e4d1774bSDmitry Karpeev     tmp2 = tmp1->next_list;
861e4d1774bSDmitry Karpeev     ierr = PetscOpFListDestroy(&tmp1);CHKERRQ(ierr);
862e4d1774bSDmitry Karpeev     tmp1 = tmp2;
863e4d1774bSDmitry Karpeev   }
864e4d1774bSDmitry Karpeev   opallhead = 0;
865e4d1774bSDmitry Karpeev   PetscFunctionReturn(0);
866e4d1774bSDmitry Karpeev }
867e4d1774bSDmitry Karpeev 
868e4d1774bSDmitry Karpeev #undef __FUNCT__
869e4d1774bSDmitry Karpeev #define __FUNCT__ "PetscOpFListFind"
870e4d1774bSDmitry Karpeev /*@C
871e4d1774bSDmitry Karpeev     PetscOpFListFind - Given a name, finds the matching op routine.
87248703020SDmitry Karpeev     Formally collective on comm.
873e4d1774bSDmitry Karpeev 
874e4d1774bSDmitry Karpeev     Input Parameters:
875e4d1774bSDmitry Karpeev +   comm     - processes looking for the op
876e4d1774bSDmitry Karpeev .   fl       - pointer to list of known ops
877e4d1774bSDmitry Karpeev .   op       - operation name
878e4d1774bSDmitry Karpeev .   numArgs  - number of op arguments
87948703020SDmitry Karpeev -   argTypes - list of argument type names
880e4d1774bSDmitry Karpeev 
881e4d1774bSDmitry Karpeev 
882e4d1774bSDmitry Karpeev     Output Parameters:
883e4d1774bSDmitry Karpeev .   r       - routine implementing op with the given arg types
884e4d1774bSDmitry Karpeev 
885e4d1774bSDmitry Karpeev     Level: developer
886e4d1774bSDmitry Karpeev 
887e4d1774bSDmitry Karpeev .seealso: PetscOpFListAdd(), PetscOpFList
888e4d1774bSDmitry Karpeev @*/
8892356f84bSDmitry Karpeev PetscErrorCode  PetscOpFListFind(MPI_Comm comm, PetscOpFList fl,PetscVoidFunction *r, const char* op, PetscInt numArgs, char* argTypes[])
890e4d1774bSDmitry Karpeev {
891e4d1774bSDmitry Karpeev   PetscOpFList   entry;
892e4d1774bSDmitry Karpeev   PetscErrorCode ierr;
893e4d1774bSDmitry Karpeev   PetscBool      match;
894e4d1774bSDmitry Karpeev   PetscInt       i;
895e4d1774bSDmitry Karpeev 
896e4d1774bSDmitry Karpeev   PetscFunctionBegin;
897e4d1774bSDmitry Karpeev   PetscValidPointer(r,3);
898e4d1774bSDmitry Karpeev   if (!op) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Attempting to find operation with null name");
899e4d1774bSDmitry Karpeev   *r = PETSC_NULL;
900*495ad40fSDmitry Karpeev   match = PETSC_FALSE;
901e4d1774bSDmitry Karpeev   entry = fl;
902e4d1774bSDmitry Karpeev   while (entry) {
903e4d1774bSDmitry Karpeev     ierr = PetscStrcmp(entry->op,op,&match); CHKERRQ(ierr);
904e4d1774bSDmitry Karpeev     if(!match) goto next;
905e4d1774bSDmitry Karpeev     if(numArgs == entry->numArgs)
906e4d1774bSDmitry Karpeev       match = PETSC_TRUE;
907e4d1774bSDmitry Karpeev     else
908e4d1774bSDmitry Karpeev       match = PETSC_FALSE;
909e4d1774bSDmitry Karpeev     if(!match) goto next;
910e4d1774bSDmitry Karpeev     if(numArgs) {
911e4d1774bSDmitry Karpeev       for(i = 0; i < numArgs; ++i) {
91248703020SDmitry Karpeev         ierr = PetscStrcmp(argTypes[i], entry->argTypes[i], &match);  CHKERRQ(ierr);
91348703020SDmitry Karpeev         if(!match) goto next;
914e4d1774bSDmitry Karpeev       }
915e4d1774bSDmitry Karpeev     }
916f3b60a6eSDmitry Karpeev     break;
917e4d1774bSDmitry Karpeev     next: entry = entry->next;
918e4d1774bSDmitry Karpeev   }
919e4d1774bSDmitry Karpeev   if (match) {
920e4d1774bSDmitry Karpeev     if (entry->routine) {
921e4d1774bSDmitry Karpeev       *r   = entry->routine;
922e4d1774bSDmitry Karpeev     }
923e4d1774bSDmitry Karpeev #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
924e4d1774bSDmitry Karpeev     else {
925e4d1774bSDmitry Karpeev       /* it is not yet in memory so load from dynamic library */
926d44a1e48SBarry Smith       ierr = PetscDLLibrarySym(comm,&PetscDLLibrariesLoaded,entry->path,entry->name,(void **)r);CHKERRQ(ierr);
927e4d1774bSDmitry Karpeev       if (*r) {
928e4d1774bSDmitry Karpeev         entry->routine = *r;
929e4d1774bSDmitry Karpeev       }
930e4d1774bSDmitry Karpeev     }
931e4d1774bSDmitry Karpeev #endif
932e4d1774bSDmitry Karpeev   }
933e4d1774bSDmitry Karpeev 
934e4d1774bSDmitry Karpeev   PetscFunctionReturn(0);
935e4d1774bSDmitry Karpeev }
936e4d1774bSDmitry Karpeev 
937e4d1774bSDmitry Karpeev #undef __FUNCT__
938e4d1774bSDmitry Karpeev #define __FUNCT__ "PetscOpFListView"
939e4d1774bSDmitry Karpeev /*@C
940e4d1774bSDmitry Karpeev    PetscOpFListView - prints out contents of a PetscOpFList
941e4d1774bSDmitry Karpeev 
942e4d1774bSDmitry Karpeev    Collective on viewer
943e4d1774bSDmitry Karpeev 
944e4d1774bSDmitry Karpeev    Input Parameters:
945e4d1774bSDmitry Karpeev +  list   - the list of functions
94648703020SDmitry Karpeev -  viewer - ASCII viewer   Level: developer
947e4d1774bSDmitry Karpeev 
948e4d1774bSDmitry Karpeev .seealso: PetscOpFListAdd(), PetscOpFList
949e4d1774bSDmitry Karpeev @*/
950e4d1774bSDmitry Karpeev PetscErrorCode  PetscOpFListView(PetscOpFList list,PetscViewer viewer)
951e4d1774bSDmitry Karpeev {
952e4d1774bSDmitry Karpeev   PetscErrorCode ierr;
953e4d1774bSDmitry Karpeev   PetscBool      iascii;
954e4d1774bSDmitry Karpeev   PetscInt       i;
955e4d1774bSDmitry Karpeev 
956e4d1774bSDmitry Karpeev   PetscFunctionBegin;
957e4d1774bSDmitry Karpeev   if (!viewer) viewer = PETSC_VIEWER_STDOUT_SELF;
958e4d1774bSDmitry Karpeev   PetscValidPointer(list,1);
959e4d1774bSDmitry Karpeev   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2);
960e4d1774bSDmitry Karpeev 
961251f4c67SDmitry Karpeev   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
962e4d1774bSDmitry Karpeev   if (!iascii) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Only ASCII viewer supported");
963e4d1774bSDmitry Karpeev 
964e4d1774bSDmitry Karpeev   while (list) {
965e4d1774bSDmitry Karpeev     if (list->url) {
966e4d1774bSDmitry Karpeev       ierr = PetscViewerASCIIPrintf(viewer," %s: ",list->url); CHKERRQ(ierr);
967e4d1774bSDmitry Karpeev     }
968e4d1774bSDmitry Karpeev     ierr = PetscViewerASCIIPrintf(viewer, "%s(", list->op);    CHKERRQ(ierr);
969e4d1774bSDmitry Karpeev     for(i = 0; i < list->numArgs;++i) {
970e4d1774bSDmitry Karpeev       if(i > 0) {
971e4d1774bSDmitry Karpeev         ierr = PetscViewerASCIIPrintf(viewer, ", "); CHKERRQ(ierr);
972e4d1774bSDmitry Karpeev       }
973e4d1774bSDmitry Karpeev       ierr = PetscViewerASCIIPrintf(viewer, "%s", list->argTypes[i]);    CHKERRQ(ierr);
974e4d1774bSDmitry Karpeev     }
975e4d1774bSDmitry Karpeev     ierr = PetscViewerASCIIPrintf(viewer, ")\n");    CHKERRQ(ierr);
976e4d1774bSDmitry Karpeev     list = list->next;
977e4d1774bSDmitry Karpeev   }
978e4d1774bSDmitry Karpeev   PetscFunctionReturn(0);
979e4d1774bSDmitry Karpeev }
980