This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Some parallel computation questions

+2 votes

I have some "print" statements. How do I execute them only on one process, say the one with rank 0 ?

I am modifying a Function like this

up1.vector()[:] += 0.01 * uppert.vector().array()

This gives error in parallel

RuntimeError: index must belong to this process, cannot index
off-process entries in a GenericVector

How can I make this correct for parallel computations ?

I read initial conditions from a file

  ups = Function(self.X)
  File("steady.xml") >> ups.vector()

Will this work correctly in parallel if steady.xml was generated by a serial run ?

asked Apr 16, 2014 by praveen FEniCS User (2,760 points)

1 Answer

+2 votes
  1. use an if statement:

    if(MPI.process_number() > 0):
    print 'hello'

  2. This looks funny to me... when I do it I do something like
    up_old.vector()[:] = up.vector()
    -> keep the .array(), which gives a numpy array, out of it. Does this statement usually work? You might want to look into axpy() too.. which I think keeps it all in vectors.

  3. no idea. Try it!!

answered Apr 17, 2014 by mwelland FEniCS User (8,410 points)

Thanks. Using .array() seemed to work but not in parallel. If I do as you suggest, it works in parallel also.

...