PETSc Problem with fgets
Barry Smith
bsmith at mcs.anl.gov
Fri May 12 13:23:09 CDT 2006
Stupid me, I don't know my own code.
You can use PetscSynchronizedFGets() exactly for this purpose.
Barry
I have updated the manual page for PetscFOpen() to seealso:
PetscSynchronizedFGets()
On Fri, 12 May 2006, Barry Smith wrote:
>
> Joshua,
>
> PetscFOpen() only produces a valid fd on process 0. Thus fgets()
> can only be used on process 0. It is crashing on process 1 because
> fd is garbage there.
>
> You need to MPI_Scatter the data to the other processes. There is
> no PetscFGets(), though come to think of it there should be! I will write
> one and send it to you.
>
> Barry
>
>
>
> On Thu, 11 May 2006, Joshua Adelman wrote:
>
>> 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