PETSc Problem with fgets
Joshua Adelman
jadelman at ocf.berkeley.edu
Thu May 11 20:28:59 CDT 2006
OK, so I changed it to PETSC_COMM_SELF, which I believe takes care of
the problem.
Thanks for your help.
Josh
On May 11, 2006, at 5:56 PM, Sh.M wrote:
> Hi,
>
> I apologize in advance if I am confusing you or down right saying
> something
> that is wrong.
>
> When I initially checked you code, it looks like CPU O is opening the
> file... but the rest of the CPUs try to read it aswell even though
> they
> havent opened(dont have a correct file pointer to the file) it
> yet... This
> would cause a segmentation fault. fgets is using the fd variable,
> wich in
> case of anything but CPU 0 are pointing to some garbage and not the
> file
> itself.
>
> With best regards, Shaman Mahmoudi
>
> ----- Original Message -----
> From: "Joshua Adelman" <jadelman at ocf.berkeley.edu>
> To: <petsc-users at mcs.anl.gov>
> Sent: Friday, May 12, 2006 12:54 AM
> Subject: PETSc Problem with fgets
>
>
>> I am trying to read some parameters into my PETSc simulation using
>> fgets, and am getting a strange error. It appears that fgets and
>> sscanf are working since the proper values are read into the
>> simulation, but it throws an error anyways. This problem only arises
>> when I am using the parallel version of the code (i.e. setting -n in
>> mpiexec to a value greater than 1). Basically if I comment everything
>> out and then start uncommenting one line at a time, the error appears
>> once I've uncommented the line with fgets. One strange thing to note
>> is that the error happens after the program has already finished
>> executing the function where the problem is. Here's a snippet of the
>> code that seems to be causing the problem:
>>
>> PetscErrorCode DataReadParams(SimData *sdata) {
>> int rank, size;
>> PetscErrorCode ierr;
>> int i;
>> FILE *fd;
>> char str[256];
>> char line[100];
>> int max = 100;
>>
>> PetscFunctionBegin;
>>
>> ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size); CHKERRQ(ierr);
>> ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank); CHKERRQ(ierr);
>>
>>
>> /* Read data from files */
>> sprintf(str,"%s%s",sdata->simname,".param");
>> ierr = PetscFOpen(PETSC_COMM_WORLD,str,"r",&fd); CHKERRQ(ierr);
>> if (!rank && !fd) {
>> SETERRQ1(PETSC_ERR_FILE_OPEN,"Cannot open %s\n",str);
>> }
>> // PetscPrintf(PETSC_COMM_WORLD,"Opening file %s\n",str);
>> fgets(line,max,fd);
>> sscanf(line,"%d",&sdata->NP);
>>
>> The error that is kicked out is:
>>
>>
>> [1]PETSC ERROR: Caught signal number 10 BUS: Bus Error, possibly
>> illegal memory access
>> [1]PETSC ERROR: Try option -start_in_debugger or -
>> on_error_attach_debugger
>> [1]PETSC ERROR: or try http://valgrind.org on linux to find memory
>> corruption errors
>> [1]PETSC ERROR: likely location of problem given in stack below
>> [1]PETSC ERROR: --------------- Stack Frames ---------------
>> [1]PETSC ERROR: Note: The EXACT line numbers in the stack are not
>> available,
>> [1]PETSC ERROR: INSTEAD the line number of the start of the
>> function
>> [1]PETSC ERROR: is given.
>> [1]PETSC ERROR: [1] DataReadParams line 23 datareadparams.c
>> [1]PETSC ERROR: [1] SimInit line 19 siminit.c
>> [1]PETSC ERROR: --------------------------------------------
>> [1]PETSC ERROR: User provided function() line 0 in unknown directory
>> unknown file
>> [1]PETSC ERROR: Signal received!
>> [1]PETSC ERROR: !
>>
>>
>> Any insight would be most appreciated.
>>
>> Josh
------------------------------------------------------------------------
------------------------------
Joshua L. Adelman
Biophysics Graduate Group Lab: 510.643.2159
218 Wellman Hall Fax: 510.642.7428
University of California, Berkeley http://www.ocf.berkeley.edu/
~jadelman
Berkeley, CA 94720 USA jadelman at ocf.berkeley.edu
------------------------------------------------------------------------
------------------------------
More information about the petsc-users
mailing list