[petsc-users] Problem with options and PetscFOpen/fopen

Oleksandr Koshkarov olk548 at mail.usask.ca
Fri Jun 8 06:44:27 CDT 2018


Never mind! Sorry I found my stupid mistake - it is not related to PETSc :)

Sorry,

Alex.


On 06/07/2018 02:46 PM, Oleksandr Koshkarov wrote:
> Hello all,
>
> I am trying to read options using petsc capabilities and it is working 
> fine.
>
> However, if I open file to read with fopen/PetscFOpen some of options 
> stopped being read.
>
> I think It may be a bug or I am doing something very stupid and cannot 
> see it.
>
> Here is the snippets of what I do:
>
> PetscBool flag;
> int path_str_size = 100;
> char str[path_str_size];
> PetscOptionsGetString(NULL,NULL,"--config",str,path_str_size,&flag);
> if (flag)
>   PetscOptionsInsert(NULL,argc,args,str);
> else
>   try_again("Please specify input file: \"--config config_path\"\n");
>
> // Loading options:
> PetscOptionsGetReal(NULL,NULL,"--dt",&(env->dt),&flag);
> if (!flag) try_again("Please specify dt: \"--dt value\"\n");
>
> ....
>
> PetscOptionsGetInt(NULL,NULL,"--Ns",&(env->Ns),&flag);
> if (!flag) try_again("Please specify Ns: \"--Ns value\"\n");
>
> for (int s; s<env->Ns; s++) {
>
>   sprintf(str,"--mass%d",s);
> PetscOptionsGetReal(NULL,NULL,str,&(env->species[s].mass),&flag);
>   if (!flag) try_again("Please specify all masses: \"--mass<N> value\" 
> (N starts from 0)\n");
>
>   ...
> }
>
>
> PetscOptionsGetString(NULL,NULL,"--grid",str,path_str_size,&flag);
> if (!flag) try_again("Please specify grid file \"--grid path\"\n");
>
>
> // This code alone works fine without a trouble!
> // but if I add next three lines, options which are in the loop 
> stopped being read (i.e., --mass0, --mass1, etc) (I am even getting a 
> warning from petsc that they are not being used
> // while other options (i.e., --dt, --Ns) are alright
> FILE *fp;
> PetscFOpen(PETSC_COMM_SELF,str,"r",&fp); // if I use fopen or 
> different variable (not str) - the same effect.
> PetscFClose(PETSC_COMM_SELF,fp);
>
> It seems it is possible to avoid this problem if you wrap 3 last lines 
> in the separate function.
>
> p.s. Am I doing something stupid?
>
> Best regards,
> Alex.
>
>



More information about the petsc-users mailing list