xref: /petsc/src/sys/dll/reg.c (revision 84df9cb40eca90ea9b18a456fab7a4ecc7f6c1a4)
1 
2 /*
3     Provides a general mechanism to allow one to register new routines in
4     dynamic libraries for many of the PETSc objects (including, e.g., KSP and PC).
5 */
6 #include <petscsys.h>           /*I "petscsys.h" I*/
7 
8 #undef __FUNCT__
9 #define __FUNCT__ "PetscFListGetPathAndFunction"
10 PetscErrorCode  PetscFListGetPathAndFunction(const char name[],char *path[],char *function[])
11 {
12   PetscErrorCode ierr;
13   char           work[PETSC_MAX_PATH_LEN],*lfunction;
14 
15   PetscFunctionBegin;
16   ierr = PetscStrncpy(work,name,256);CHKERRQ(ierr);
17   ierr = PetscStrchr(work,':',&lfunction);CHKERRQ(ierr);
18   if (lfunction != work && lfunction && lfunction[1] != ':') {
19     lfunction[0] = 0;
20     ierr = PetscStrallocpy(work,path);CHKERRQ(ierr);
21     ierr = PetscStrallocpy(lfunction+1,function);CHKERRQ(ierr);
22   } else {
23     *path = 0;
24     ierr = PetscStrallocpy(name,function);CHKERRQ(ierr);
25   }
26   PetscFunctionReturn(0);
27 }
28 
29 /*
30     This is the default list used by PETSc with the PetscDLLibrary register routines
31 */
32 PetscDLLibrary DLLibrariesLoaded = 0;
33 
34 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
35 
36 #undef __FUNCT__
37 #define __FUNCT__ "PetscLoadDynamicLibrary"
38 static PetscErrorCode  PetscLoadDynamicLibrary(const char *name,PetscBool  *found)
39 {
40   char           libs[PETSC_MAX_PATH_LEN],dlib[PETSC_MAX_PATH_LEN];
41   PetscErrorCode ierr;
42 
43   PetscFunctionBegin;
44   ierr = PetscStrcpy(libs,"${PETSC_LIB_DIR}/libpetsc");CHKERRQ(ierr);
45   ierr = PetscStrcat(libs,name);CHKERRQ(ierr);
46   ierr = PetscDLLibraryRetrieve(PETSC_COMM_WORLD,libs,dlib,1024,found);CHKERRQ(ierr);
47   if (*found) {
48     ierr = PetscDLLibraryAppend(PETSC_COMM_WORLD,&DLLibrariesLoaded,dlib);CHKERRQ(ierr);
49   } else {
50     ierr = PetscStrcpy(libs,"${PETSC_DIR}/${PETSC_ARCH}/lib/libpetsc");CHKERRQ(ierr);
51     ierr = PetscStrcat(libs,name);CHKERRQ(ierr);
52     ierr = PetscDLLibraryRetrieve(PETSC_COMM_WORLD,libs,dlib,1024,found);CHKERRQ(ierr);
53     if (*found) {
54       ierr = PetscDLLibraryAppend(PETSC_COMM_WORLD,&DLLibrariesLoaded,dlib);CHKERRQ(ierr);
55     }
56   }
57   PetscFunctionReturn(0);
58 }
59 
60 #endif
61 
62 #undef __FUNCT__
63 #define __FUNCT__ "PetscInitialize_DynamicLibraries"
64 /*
65     PetscInitialize_DynamicLibraries - Adds the default dynamic link libraries to the
66     search path.
67 */
68 PetscErrorCode  PetscInitialize_DynamicLibraries(void)
69 {
70   char           *libname[32];
71   PetscErrorCode ierr;
72   PetscInt       nmax,i;
73 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
74   PetscBool      found;
75 #endif
76 
77   PetscFunctionBegin;
78   nmax = 32;
79   ierr = PetscOptionsGetStringArray(PETSC_NULL,"-dll_prepend",libname,&nmax,PETSC_NULL);CHKERRQ(ierr);
80   for (i=0; i<nmax; i++) {
81     ierr = PetscDLLibraryPrepend(PETSC_COMM_WORLD,&DLLibrariesLoaded,libname[i]);CHKERRQ(ierr);
82     ierr = PetscFree(libname[i]);CHKERRQ(ierr);
83   }
84 
85 #if !defined(PETSC_USE_DYNAMIC_LIBRARIES)
86   /*
87       This just initializes the most basic PETSc stuff.
88 
89     The classes, from PetscDraw to PetscTS, are initialized the first
90     time an XXCreate() is called.
91   */
92   ierr = PetscSysInitializePackage(PETSC_NULL);CHKERRQ(ierr);
93 #else
94 #if defined(PETSC_USE_SINGLE_LIBRARY)
95   ierr = PetscLoadDynamicLibrary("",&found);CHKERRQ(ierr);
96   if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc dynamic library \n You cannot move the dynamic libraries!");
97 #else
98   ierr = PetscLoadDynamicLibrary("sys",&found);CHKERRQ(ierr);
99   if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc dynamic library \n You cannot move the dynamic libraries!");
100   ierr = PetscLoadDynamicLibrary("vec",&found);CHKERRQ(ierr);
101   if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc Vec dynamic library \n You cannot move the dynamic libraries!");
102   ierr = PetscLoadDynamicLibrary("mat",&found);CHKERRQ(ierr);
103   if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc Mat dynamic library \n You cannot move the dynamic libraries!");
104   ierr = PetscLoadDynamicLibrary("dm",&found);CHKERRQ(ierr);
105   if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc DM dynamic library \n You cannot move the dynamic libraries!");
106   ierr = PetscLoadDynamicLibrary("characteristic",&found);CHKERRQ(ierr);
107   if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc Characteristic dynamic library \n You cannot move the dynamic libraries!");
108   ierr = PetscLoadDynamicLibrary("ksp",&found);CHKERRQ(ierr);
109   if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc KSP dynamic library \n You cannot move the dynamic libraries!");
110   ierr = PetscLoadDynamicLibrary("snes",&found);CHKERRQ(ierr);
111   if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc SNES dynamic library \n You cannot move the dynamic libraries!");
112   ierr = PetscLoadDynamicLibrary("ts",&found);CHKERRQ(ierr);
113   if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc TS dynamic library \n You cannot move the dynamic libraries!");
114 #endif
115 
116   ierr = PetscLoadDynamicLibrary("mesh",&found);CHKERRQ(ierr);
117   ierr = PetscLoadDynamicLibrary("contrib",&found);CHKERRQ(ierr);
118 #endif
119 
120   nmax = 32;
121   ierr = PetscOptionsGetStringArray(PETSC_NULL,"-dll_append",libname,&nmax,PETSC_NULL);CHKERRQ(ierr);
122   for (i=0; i<nmax; i++) {
123     ierr = PetscDLLibraryAppend(PETSC_COMM_WORLD,&DLLibrariesLoaded,libname[i]);CHKERRQ(ierr);
124     ierr = PetscDLLibraryCCAAppend(PETSC_COMM_WORLD,&DLLibrariesLoaded,libname[i]);CHKERRQ(ierr);
125     ierr = PetscFree(libname[i]);CHKERRQ(ierr);
126   }
127 
128   PetscFunctionReturn(0);
129 }
130 
131 #undef __FUNCT__
132 #define __FUNCT__ "PetscFinalize_DynamicLibraries"
133 /*
134      PetscFinalize_DynamicLibraries - Closes the opened dynamic libraries.
135 */
136 PetscErrorCode PetscFinalize_DynamicLibraries(void)
137 {
138   PetscErrorCode ierr;
139   PetscBool      flg = PETSC_FALSE;
140 
141   PetscFunctionBegin;
142   ierr = PetscOptionsGetBool(PETSC_NULL,"-dll_view",&flg,PETSC_NULL);CHKERRQ(ierr);
143   if (flg) { ierr = PetscDLLibraryPrintPath(DLLibrariesLoaded);CHKERRQ(ierr); }
144   ierr = PetscDLLibraryClose(DLLibrariesLoaded);CHKERRQ(ierr);
145   DLLibrariesLoaded = 0;
146   PetscFunctionReturn(0);
147 }
148 
149 /* ------------------------------------------------------------------------------*/
150 struct _n_PetscFList {
151   void        (*routine)(void);   /* the routine */
152   char        *path;              /* path of link library containing routine */
153   char        *name;              /* string to identify routine */
154   char        *rname;             /* routine name in dynamic library */
155   PetscFList  next;               /* next pointer */
156   PetscFList  next_list;          /* used to maintain list of all lists for freeing */
157 };
158 
159 /*
160      Keep a linked list of PetscFLists so that we can destroy all the left-over ones.
161 */
162 static PetscFList   dlallhead = 0;
163 
164 #undef __FUNCT__
165 #define __FUNCT__ "PetscFListAdd"
166 /*@C
167    PetscFListAddDynamic - Given a routine and a string id, saves that routine in the
168    specified registry.
169 
170      Not Collective
171 
172    Input Parameters:
173 +  fl    - pointer registry
174 .  name  - string to identify routine
175 .  rname - routine name in dynamic library
176 -  fnc   - function pointer (optional if using dynamic libraries)
177 
178    Notes:
179    To remove a registered routine, pass in a PETSC_NULL rname and fnc().
180 
181    Users who wish to register new classes for use by a particular PETSc
182    component (e.g., SNES) should generally call the registration routine
183    for that particular component (e.g., SNESRegisterDynamic()) instead of
184    calling PetscFListAddDynamic() directly.
185 
186    ${PETSC_ARCH}, ${PETSC_DIR}, ${PETSC_LIB_DIR}, or ${any environmental variable}
187   occuring in pathname will be replaced with appropriate values.
188 
189    Level: developer
190 
191 .seealso: PetscFListDestroy(), SNESRegisterDynamic(), KSPRegisterDynamic(),
192           PCRegisterDynamic(), TSRegisterDynamic(), PetscFList
193 @*/
194 PetscErrorCode  PetscFListAdd(PetscFList *fl,const char name[],const char rname[],void (*fnc)(void))
195 {
196   PetscFList     entry,ne;
197   PetscErrorCode ierr;
198   char           *fpath,*fname;
199 
200   PetscFunctionBegin;
201   if (!*fl) {
202     ierr           = PetscNew(struct _n_PetscFList,&entry);CHKERRQ(ierr);
203     ierr           = PetscStrallocpy(name,&entry->name);CHKERRQ(ierr);
204     ierr           = PetscFListGetPathAndFunction(rname,&fpath,&fname);CHKERRQ(ierr);
205     entry->path    = fpath;
206     entry->rname   = fname;
207     entry->routine = fnc;
208     entry->next    = 0;
209     *fl = entry;
210 
211     /* add this new list to list of all lists */
212     if (!dlallhead) {
213       dlallhead        = *fl;
214       (*fl)->next_list = 0;
215     } else {
216       ne               = dlallhead;
217       dlallhead        = *fl;
218       (*fl)->next_list = ne;
219     }
220   } else {
221     /* search list to see if it is already there */
222     ne = *fl;
223     while (ne) {
224       PetscBool  founddup;
225 
226       ierr = PetscStrcmp(ne->name,name,&founddup);CHKERRQ(ierr);
227       if (founddup) { /* found duplicate */
228         ierr = PetscFListGetPathAndFunction(rname,&fpath,&fname);CHKERRQ(ierr);
229         ierr = PetscFree(ne->path);CHKERRQ(ierr);
230         ierr = PetscFree(ne->rname);CHKERRQ(ierr);
231         ne->path    = fpath;
232         ne->rname   = fname;
233         ne->routine = fnc;
234         PetscFunctionReturn(0);
235       }
236       if (ne->next) ne = ne->next; else break;
237     }
238     /* create new entry and add to end of list */
239     ierr           = PetscNew(struct _n_PetscFList,&entry);CHKERRQ(ierr);
240     ierr           = PetscStrallocpy(name,&entry->name);CHKERRQ(ierr);
241     ierr           = PetscFListGetPathAndFunction(rname,&fpath,&fname);CHKERRQ(ierr);
242     entry->path    = fpath;
243     entry->rname   = fname;
244     entry->routine = fnc;
245     entry->next    = 0;
246     ne->next       = entry;
247   }
248   PetscFunctionReturn(0);
249 }
250 
251 #undef __FUNCT__
252 #define __FUNCT__ "PetscFListDestroy"
253 /*@
254     PetscFListDestroy - Destroys a list of registered routines.
255 
256     Input Parameter:
257 .   fl  - pointer to list
258 
259     Level: developer
260 
261 .seealso: PetscFListAddDynamic(), PetscFList
262 @*/
263 PetscErrorCode  PetscFListDestroy(PetscFList *fl)
264 {
265   PetscFList     next,entry,tmp = dlallhead;
266   PetscErrorCode ierr;
267 
268   PetscFunctionBegin;
269   if (!*fl) PetscFunctionReturn(0);
270   if (!dlallhead) PetscFunctionReturn(0);
271 
272   /*
273        Remove this entry from the master DL list (if it is in it)
274   */
275   if (dlallhead == *fl) {
276     if (dlallhead->next_list) {
277       dlallhead = dlallhead->next_list;
278     } else {
279       dlallhead = 0;
280     }
281   } else {
282     while (tmp->next_list != *fl) {
283       tmp = tmp->next_list;
284       if (!tmp->next_list) break;
285     }
286     if (tmp->next_list) tmp->next_list = tmp->next_list->next_list;
287   }
288 
289   /* free this list */
290   entry = *fl;
291   while (entry) {
292     next = entry->next;
293     ierr = PetscFree(entry->path);CHKERRQ(ierr);
294     ierr = PetscFree(entry->name);CHKERRQ(ierr);
295     ierr = PetscFree(entry->rname);CHKERRQ(ierr);
296     ierr = PetscFree(entry);CHKERRQ(ierr);
297     entry = next;
298   }
299   *fl = 0;
300   PetscFunctionReturn(0);
301 }
302 
303 /*
304    Destroys all the function lists that anyone has every registered, such as KSPList, VecList, etc.
305 */
306 #undef __FUNCT__
307 #define __FUNCT__ "PetscFListDestroyAll"
308 PetscErrorCode  PetscFListDestroyAll(void)
309 {
310   PetscFList     tmp2,tmp1 = dlallhead;
311   PetscErrorCode ierr;
312 
313   PetscFunctionBegin;
314   while (tmp1) {
315     tmp2 = tmp1->next_list;
316     ierr = PetscFListDestroy(&tmp1);CHKERRQ(ierr);
317     tmp1 = tmp2;
318   }
319   dlallhead = 0;
320   PetscFunctionReturn(0);
321 }
322 
323 #undef __FUNCT__
324 #define __FUNCT__ "PetscFListFind"
325 /*@C
326     PetscFListFind - Given a name, finds the matching routine.
327 
328     Input Parameters:
329 +   fl   - pointer to list
330 .   comm - processors looking for routine
331 .   name - name string
332 -   searchlibraries - if not found in the list then search the dynamic libraries and executable for the symbol
333 
334     Output Parameters:
335 .   r - the routine
336 
337     Level: developer
338 
339 .seealso: PetscFListAddDynamic(), PetscFList
340 @*/
341 PetscErrorCode  PetscFListFind(PetscFList fl,MPI_Comm comm,const char name[],PetscBool searchlibraries,void (**r)(void))
342 {
343   PetscFList     entry = fl;
344   PetscErrorCode ierr;
345   char           *function,*path;
346   PetscBool      flg,f1,f2,f3;
347 #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
348   char           *newpath;
349 #endif
350 
351   PetscFunctionBegin;
352   if (!name) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to find routine with null name");
353 
354   *r = 0;
355   ierr = PetscFListGetPathAndFunction(name,&path,&function);CHKERRQ(ierr);
356 
357   /*
358         If path then append it to search libraries
359   */
360 #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
361   if (path) {
362     ierr = PetscDLLibraryAppend(comm,&DLLibrariesLoaded,path);CHKERRQ(ierr);
363   }
364 #endif
365 
366   while (entry) {
367     flg = PETSC_FALSE;
368     if (path && entry->path) {
369       ierr = PetscStrcmp(path,entry->path,&f1);CHKERRQ(ierr);
370       ierr = PetscStrcmp(function,entry->rname,&f2);CHKERRQ(ierr);
371       ierr = PetscStrcmp(function,entry->name,&f3);CHKERRQ(ierr);
372       flg =  (PetscBool) ((f1 && f2) || (f1 && f3));
373     } else if (!path) {
374       ierr = PetscStrcmp(function,entry->name,&f1);CHKERRQ(ierr);
375       ierr = PetscStrcmp(function,entry->rname,&f2);CHKERRQ(ierr);
376       flg =  (PetscBool) (f1 || f2);
377     } else {
378       ierr = PetscStrcmp(function,entry->name,&flg);CHKERRQ(ierr);
379       if (flg) {
380         ierr = PetscFree(function);CHKERRQ(ierr);
381         ierr = PetscStrallocpy(entry->rname,&function);CHKERRQ(ierr);
382       } else {
383         ierr = PetscStrcmp(function,entry->rname,&flg);CHKERRQ(ierr);
384       }
385     }
386 
387     if (flg) {
388       if (entry->routine) {
389         *r   = entry->routine;
390         ierr = PetscFree(path);CHKERRQ(ierr);
391         ierr = PetscFree(function);CHKERRQ(ierr);
392         PetscFunctionReturn(0);
393       }
394       if (!(entry->rname && entry->rname[0])) { /* The entry has been cleared */
395         ierr = PetscFree(function);CHKERRQ(ierr);
396         PetscFunctionReturn(0);
397       }
398       if ((path && entry->path && f3) || (!path && f1)) { /* convert name of function (alias) to actual function name */
399         ierr = PetscFree(function);CHKERRQ(ierr);
400         ierr = PetscStrallocpy(entry->rname,&function);CHKERRQ(ierr);
401       }
402 
403       /* it is not yet in memory so load from dynamic library */
404 #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
405       newpath = path;
406       if (!path) newpath = entry->path;
407       ierr = PetscDLLibrarySym(comm,&DLLibrariesLoaded,newpath,entry->rname,(void **)r);CHKERRQ(ierr);
408       if (*r) {
409         entry->routine = *r;
410         ierr = PetscFree(path);CHKERRQ(ierr);
411         ierr = PetscFree(function);CHKERRQ(ierr);
412         PetscFunctionReturn(0);
413       }
414 #endif
415     }
416     entry = entry->next;
417   }
418 
419 #if defined(PETSC_HAVE_DYNAMIC_LIBRARIES)
420   if (searchlibraries) {
421     /* Function never registered; try for it anyway */
422     ierr = PetscDLLibrarySym(comm,&DLLibrariesLoaded,path,function,(void **)r);CHKERRQ(ierr);
423     ierr = PetscFree(path);CHKERRQ(ierr);
424     if (*r) {
425       ierr = PetscFListAdd(&fl,name,name,*r);CHKERRQ(ierr);
426     }
427   }
428 #endif
429   ierr = PetscFree(function);CHKERRQ(ierr);
430   PetscFunctionReturn(0);
431 }
432 
433 #undef __FUNCT__
434 #define __FUNCT__ "PetscFListView"
435 /*@
436    PetscFListView - prints out contents of an PetscFList
437 
438    Collective over MPI_Comm
439 
440    Input Parameters:
441 +  list - the list of functions
442 -  viewer - currently ignored
443 
444    Level: developer
445 
446 .seealso: PetscFListAddDynamic(), PetscFListPrintTypes(), PetscFList
447 @*/
448 PetscErrorCode  PetscFListView(PetscFList list,PetscViewer viewer)
449 {
450   PetscErrorCode ierr;
451   PetscBool      iascii;
452 
453   PetscFunctionBegin;
454   if (!viewer) viewer = PETSC_VIEWER_STDOUT_SELF;
455   PetscValidPointer(list,1);
456   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2);
457 
458   ierr = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
459   if (!iascii) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Only ASCII viewer supported");
460 
461   while (list) {
462     if (list->path) {
463       ierr = PetscViewerASCIIPrintf(viewer," %s %s %s\n",list->path,list->name,list->rname);CHKERRQ(ierr);
464     } else {
465       ierr = PetscViewerASCIIPrintf(viewer," %s %s\n",list->name,list->rname);CHKERRQ(ierr);
466     }
467     list = list->next;
468   }
469   ierr = PetscViewerASCIIPrintf(viewer,"\n");CHKERRQ(ierr);
470   PetscFunctionReturn(0);
471 }
472 
473 #undef __FUNCT__
474 #define __FUNCT__ "PetscFListGet"
475 /*@
476    PetscFListGet - Gets an array the contains the entries in PetscFList, this is used
477          by help etc.
478 
479    Collective over MPI_Comm
480 
481    Input Parameter:
482 .  list   - list of types
483 
484    Output Parameter:
485 +  array - array of names
486 -  n - length of array
487 
488    Notes:
489        This allocates the array so that must be freed. BUT the individual entries are
490     not copied so should not be freed.
491 
492    Level: developer
493 
494 .seealso: PetscFListAddDynamic(), PetscFList
495 @*/
496 PetscErrorCode  PetscFListGet(PetscFList list,char ***array,int *n)
497 {
498   PetscErrorCode ierr;
499   PetscInt       count = 0;
500   PetscFList     klist = list;
501 
502   PetscFunctionBegin;
503   while (list) {
504     list = list->next;
505     count++;
506   }
507   ierr  = PetscMalloc((count+1)*sizeof(char *),array);CHKERRQ(ierr);
508   count = 0;
509   while (klist) {
510     (*array)[count] = klist->name;
511     klist = klist->next;
512     count++;
513   }
514   (*array)[count] = 0;
515   *n = count+1;
516   PetscFunctionReturn(0);
517 }
518 
519 
520 #undef __FUNCT__
521 #define __FUNCT__ "PetscFListPrintTypes"
522 /*@C
523    PetscFListPrintTypes - Prints the methods available.
524 
525    Collective over MPI_Comm
526 
527    Input Parameters:
528 +  comm   - the communicator (usually MPI_COMM_WORLD)
529 .  fd     - file to print to, usually stdout
530 .  prefix - prefix to prepend to name (optional)
531 .  name   - option string (for example, "-ksp_type")
532 .  text - short description of the object (for example, "Krylov solvers")
533 .  man - name of manual page that discusses the object (for example, "KSPCreate")
534 .  list   - list of types
535 -  def - default (current) value
536 
537    Level: developer
538 
539 .seealso: PetscFListAddDynamic(), PetscFList
540 @*/
541 PetscErrorCode  PetscFListPrintTypes(MPI_Comm comm,FILE *fd,const char prefix[],const char name[],const char text[],const char man[],PetscFList list,const char def[])
542 {
543   PetscErrorCode ierr;
544   PetscInt       count = 0;
545   char           p[64];
546 
547   PetscFunctionBegin;
548   if (!fd) fd = PETSC_STDOUT;
549 
550   ierr = PetscStrcpy(p,"-");CHKERRQ(ierr);
551   if (prefix) {ierr = PetscStrcat(p,prefix);CHKERRQ(ierr);}
552   ierr = PetscFPrintf(comm,fd,"  %s%s <%s>: %s (one of)",p,name+1,def,text);CHKERRQ(ierr);
553 
554   while (list) {
555     ierr = PetscFPrintf(comm,fd," %s",list->name);CHKERRQ(ierr);
556     list = list->next;
557     count++;
558     if (count == 8) {ierr = PetscFPrintf(comm,fd,"\n     ");CHKERRQ(ierr);}
559   }
560   ierr = PetscFPrintf(comm,fd," (%s)\n",man);CHKERRQ(ierr);
561   PetscFunctionReturn(0);
562 }
563 
564 #undef __FUNCT__
565 #define __FUNCT__ "PetscFListDuplicate"
566 /*@
567     PetscFListDuplicate - Creates a new list from a given object list.
568 
569     Input Parameters:
570 .   fl   - pointer to list
571 
572     Output Parameters:
573 .   nl - the new list (should point to 0 to start, otherwise appends)
574 
575     Level: developer
576 
577 .seealso: PetscFList, PetscFListAdd(), PetscFlistDestroy()
578 
579 @*/
580 PetscErrorCode  PetscFListDuplicate(PetscFList fl,PetscFList *nl)
581 {
582   PetscErrorCode ierr;
583   char           path[PETSC_MAX_PATH_LEN];
584 
585   PetscFunctionBegin;
586   while (fl) {
587     /* this is silly, rebuild the complete pathname */
588     if (fl->path) {
589       ierr = PetscStrcpy(path,fl->path);CHKERRQ(ierr);
590       ierr = PetscStrcat(path,":");CHKERRQ(ierr);
591       ierr = PetscStrcat(path,fl->name);CHKERRQ(ierr);
592     } else {
593       ierr = PetscStrcpy(path,fl->name);CHKERRQ(ierr);
594     }
595     ierr = PetscFListAdd(nl,path,fl->rname,fl->routine);CHKERRQ(ierr);
596     fl   = fl->next;
597   }
598   PetscFunctionReturn(0);
599 }
600 
601 
602 #undef __FUNCT__
603 #define __FUNCT__ "PetscFListConcat"
604 /*
605     PetscFListConcat - joins name of a libary, and the path where it is located
606     into a single string.
607 
608     Input Parameters:
609 .   path   - path to the library name.
610 .   name   - name of the library
611 
612     Output Parameters:
613 .   fullname - the name that is the union of the path and the library name,
614                delimited by a semicolon, i.e., path:name
615 
616     Notes:
617     If the path is NULL, assumes that the name, specified also includes
618     the path as path:name
619 
620 */
621 PetscErrorCode  PetscFListConcat(const char path[],const char name[],char fullname[])
622 {
623   PetscErrorCode ierr;
624   PetscFunctionBegin;
625   if (path) {
626     ierr = PetscStrcpy(fullname,path);CHKERRQ(ierr);
627     ierr = PetscStrcat(fullname,":");CHKERRQ(ierr);
628     ierr = PetscStrcat(fullname,name);CHKERRQ(ierr);
629   } else {
630     ierr = PetscStrcpy(fullname,name);CHKERRQ(ierr);
631   }
632   PetscFunctionReturn(0);
633 }
634