<div dir="ltr">On Sat, Nov 9, 2013 at 6:09 PM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
   As Jed has already noted I have an extremely ugly branch barry/make-petscoptionsobject-nonglobal which was a minimal effort change to get the PetscOptions… code to not use any global variables. I made PetscOptionsObject be inside the PetscOptionsBegin() macro but tried to hide it from the API and secretly pass it to the PetscOptionsInt() etc function. But it cannot be completely secret since it has to be passed to things like (*obj->setfromoptions)()<br>

<br>
 I had to make it even uglier by having PetscInitialize() call<br>
<br>
+<br>
+  ierr = PetscThreadCommInitializePackage();CHKERRQ(ierr);<br>
+  ierr = PetscThreadCommWorldInitialize();CHKERRQ(ierr);<br>
+  ierr = AOInitializePackage();CHKERRQ(ierr);<br>
+  ierr = PetscSFInitializePackage();CHKERRQ(ierr);<br>
+  ierr = CharacteristicInitializePackage();CHKERRQ(ierr);<br>
+  ierr = ISInitializePackage();CHKERRQ(ierr);<br>
+  ierr = VecInitializePackage();CHKERRQ(ierr);<br>
+  ierr = MatInitializePackage();CHKERRQ(ierr);<br>
+  ierr = DMInitializePackage();CHKERRQ(ierr);<br>
+  ierr = PCInitializePackage();CHKERRQ(ierr);<br>
+  ierr = KSPInitializePackage();CHKERRQ(ierr);<br>
+  ierr = SNESInitializePackage();CHKERRQ(ierr);<br>
+  ierr = TSInitializePackage();CHKERRQ(ierr);<br>
+  {<br>
+    MPI_Comm comm;<br>
+    ierr = PetscCommDuplicate(PETSC_COMM_SELF,&comm,NULL);CHKERRQ(ierr);<br>
+    ierr = PetscCommDuplicate(PETSC_COMM_WORLD,&comm,NULL);CHKERRQ(ierr);<br>
+  }<br>
<br>
  since they all set global variables and thus having multiple threads around would cause grief.<br>
<br>
   I have two questions<br>
<br>
   1) Currently PetscOptionsObject is sometimes hidden and sometimes visible. I propose making it completely visible, the code would declare the variable before calling PetscOptionsBegin() then actually pass it into the various PetscOptionsInt() etc as opposed to secretly passing it in.  Sound OK?<br>
</blockquote><div><br></div><div>Yes.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
   2) We need a way for initializing all the packages in PetscInitialize() instead of as needed. In master I see<br></blockquote><div><br></div><div>I really do not like this since then we are creating circular dependencies, and people who would like to "use</div>
<div>only a part" will be upset. What about having the user who wants completely threadsafe stuff call *Initialize(),</div><div>and then have this cascade all the way down (I think it should anyway).</div><div><br></div>
<div>   Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
#if !defined(PETSC_HAVE_DYNAMIC_LIBRARIES)<br>
  /*<br>
      This just initializes the most basic PETSc stuff.<br>
<br>
    The classes, from PetscDraw to PetscTS, are initialized the first<br>
    time an XXCreate() is called.<br>
  */<br>
  ierr = PetscSysInitializePackage();CHKERRQ(ierr);<br>
#else<br>
  preload = PETSC_FALSE;<br>
  ierr = PetscOptionsGetBool(NULL,"-dynamic_library_preload",&preload,NULL);CHKERRQ(ierr);<br>
  if (preload) {<br>
    PetscBool found;<br>
#if defined(PETSC_USE_SINGLE_LIBRARY)<br>
<br>
   Is this suppose to be here? Or is there some branch that does it differently that is not yet in master? We could change the -dynamic_library_preload flag to something more general like -initialize_all_on_start (need better name) that forces all the initializations for both dynamic and not. This will mess up the multiple PETSc library case, how will we deal with that? So, how should we force initialization of everything at start up?<br>

<br>
   Thanks<br>
<span class="HOEnZb"><font color="#888888"><br>
   Barry<br>
<br>
<br>
<br>
<br>
<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener
</div></div>