I have a system of equations: a11*x1 + a12*x2 + ... + a1n*xn = b1 a21*x1 + a22*x2 + ... + a2n*xn = b2 . . . an1*x1 + an2*x2 + ... + ann*xn = bn
Let's say I want to modify the first equation, but I don't want to lose the information there, so I will add first the first and second equations, store the result in the second equation and then modify the first equation. Like this: x1 - x2 = 0 (a11+a21)*x1 + (a12+a22)*x2 + ... + (a1n+a2n)*xn = b1+b2 . . . an1*x1 + an2*x2 + ... + ann*xn = bn And I want to do this for a few rows of my matrix. I have already built the nonzero structure so that these additions can be done without hitting a non preallocated location (for example a case where a21 was never allocated because it was meant to be zero always and now, with a11 present, it's different than zero). Any hints? Thanks! Carles El dia 19/11/2015 19:55, "Barry Smith" <[email protected]> va escriure: > > > On Nov 19, 2015, at 11:25 AM, Carles Bona <[email protected]> wrote: > > > > Dear all, > > > > I would like to add some of my equations before I modify them. > > Please explain what you mean by this. Algebraically exactly what do you > want to do? > > > > I haven't found any high level function that would allow me to add rows > of a matrix (I am working with a parallel BAIJ). Is there any nice way of > doing this? > > > > I have tried with MatGetRow/MatRestoreRow, but I am struggling a bit to > retain the cols and vals, as only one processor can call MatGetRow but if > only that processor tries to allocate memory then one gets a segmentation > fault. I guess I should allocate enough memory on all processors... > > > > If I refrain from storing the cols and vals I need to call MatSetValues > before returning the pointer, with a subsequent call to assemblybegin/end > for each row, which slows down the code. > > > > The other option would be to forget about these row additions after the > matrix has been filled and try to fill it while taking into account these > row additions at the same time. I guess I need to be constantly checking > for indices then. > > > > So, which option (not necessarily mentioned here) would you reccomend? > > > > Thanks a lot, > > > > Carles > >
