Following your comments, that works in multi processes. After extracting procedure from 'newmat' which is submatrix.
PetscInt *indices; PetscMalloc1(1, &indices); Indices[0] = 0; ISCreateGenreral(PETSC_COMM_WORLD, 1, indices, PETSC_OWN_POINTER, &isrow); MatCreateSubMatrix(mat,isrow,NULL,MAT_INITIAL_MATRIX,&newmat); (extract from newmat) I did 'ISDestroy(&isrow); PetscFree(indices);' However I got an error 'double free'. So I deleted PetscFree. Is this correct response of that error? If not, how should I deal with that error?? Thanks, Hyung Kim 2023년 2월 3일 (금) 오후 11:33, Matthew Knepley <[email protected]>님이 작성: > On Fri, Feb 3, 2023 at 9:04 AM 김성익 <[email protected]> wrote: > >> Actually in the last mail, below scripts are running in all processes. >> >> IS isrow; >> PetscInt *indices; >> PetscMalloc1(1, &indices); >> Indices[0] = 0; >> ISCreateGenreral(PETSC_COMM_WORLD, 1, indices, PETSC_OWN_POINTER, &isrow); >> MatCreateSubMatrix(mat,isrow,NULL,MAT_INITIAL_MATRIX,&newmat); >> (extract from newmat) >> >> However, you said it cannot get the values of first row of global matrix. >> Please let me know how can I fix this scripts for getting the 1st row of >> global matrix in all processes. >> > > Did you run and see what you get? If it is on all processes, it should > work. > > Thanks, > > Matt > > >> Hyung Kim >> >> >> >> >> >> >> >> 2023년 2월 3일 (금) 오후 10:54, Matthew Knepley <[email protected]>님이 작성: >> >>> On Fri, Feb 3, 2023 at 8:52 AM 김성익 <[email protected]> wrote: >>> >>>> I want to extract same row values of global matrix in all processes. >>>> Then how can I do this?? >>>> >>> >>> Create the same IS on each process. >>> >>> THanks, >>> >>> Matt >>> >>> >>>> The case of same problem of vector, I just use vecscattertoall. >>>> However, I can't find same function for matrix. >>>> >>>> Hyung Kim >>>> >>>> 2023년 2월 3일 (금) 오후 10:47, Matthew Knepley <[email protected]>님이 작성: >>>> >>>>> On Fri, Feb 3, 2023 at 8:45 AM 김성익 <[email protected]> wrote: >>>>> >>>>>> Following your comments, >>>>>> If I extract first row of below matrix. >>>>>> [image: image.png] >>>>>> IS isrow; >>>>>> PetscInt *indices; >>>>>> PetscMalloc1(1, *indices); >>>>>> >>>>> >>>>> That should be &indices. >>>>> >>>>> >>>>>> Indices[0] = 0; >>>>>> ISCreateGenreral(PETSC_COMM_WORLD, 1, indices, PETSC_COPY_VALUES, >>>>>> &isrow); >>>>>> >>>>> >>>>> You should use PETSC_OWN_POINTER. >>>>> >>>>> >>>>>> MatCreateSubMatrix(mat,isrow,NULL,MAT_INITIAL_MATRIX,&newmat); >>>>>> >>>>>> Then can I get the array about first row of global matrix in all >>>>>> processes? >>>>>> >>>>> >>>>> No, just on the process which gives 0. If you do that on every >>>>> process, every rank with get row 0. >>>>> >>>>> Thanks, >>>>> >>>>> Matt >>>>> >>>>> >>>>>> Hyung Kim >>>>>> >>>>>> 2023년 2월 3일 (금) 오후 10:26, Matthew Knepley <[email protected]>님이 작성: >>>>>> >>>>>>> On Fri, Feb 3, 2023 at 8:06 AM 김성익 <[email protected]> wrote: >>>>>>> >>>>>>>> Following your comments, >>>>>>>> I want to check below things. >>>>>>>> For example, the global dense matrix are as below. >>>>>>>> [image: image.png] >>>>>>>> If I want to get first row ('1 2 0 0 3 0 0 4') in Proc 1. >>>>>>>> Then I should put 'MatCreateSubMatrix >>>>>>>> <https://petsc.org/main/docs/manualpages/Mat/MatCreateSubMatrix/>( >>>>>>>> mat, isrow, NULL, MAT_INITIAL_MATRIX, *&*newmat)' >>>>>>>> and isrow will be [0 1 2 3 4 5 6 7]. >>>>>>>> >>>>>>>> In this case, How can I make isrow? >>>>>>>> Actually I can't understand the procedure of handling isrow. >>>>>>>> >>>>>>> >>>>>>> You create an IS object of type ISGENERAL and give it the array of >>>>>>> global indices that you want to extract. >>>>>>> >>>>>>> Thanks, >>>>>>> >>>>>>> Matt >>>>>>> >>>>>>> >>>>>>>> Hyung Kim >>>>>>>> >>>>>>>> 2023년 2월 3일 (금) 오후 9:03, Mark Adams <[email protected]>님이 작성: >>>>>>>> >>>>>>>>> https://petsc.org/main/docs/manualpages/Mat/MatCreateSubMatrix/ >>>>>>>>> >>>>>>>>> Note, PETSc lets you give NULL arguments if there is a reasonable >>>>>>>>> default. >>>>>>>>> In this case give NULL for the column IS and you will get the >>>>>>>>> whole columns. >>>>>>>>> >>>>>>>>> Mark >>>>>>>>> >>>>>>>>> On Fri, Feb 3, 2023 at 4:05 AM 김성익 <[email protected]> wrote: >>>>>>>>> >>>>>>>>>> Hello, >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> By using MatGetRow, user can get vectors from local matrix (at >>>>>>>>>> each process). >>>>>>>>>> >>>>>>>>>> However, I need other process's row values. >>>>>>>>>> So I have 2 questions. >>>>>>>>>> >>>>>>>>>> 1. Is there any function for getting arrays from other process's?? >>>>>>>>>> >>>>>>>>>> 2. Or is there any function like matrix version of >>>>>>>>>> vecscattertoall?? >>>>>>>>>> >>>>>>>>>> Thanks, >>>>>>>>>> Hyung Kim >>>>>>>>>> >>>>>>>>> >>>>>>> >>>>>>> -- >>>>>>> What most experimenters take for granted before they begin their >>>>>>> experiments is infinitely more interesting than any results to which >>>>>>> their >>>>>>> experiments lead. >>>>>>> -- Norbert Wiener >>>>>>> >>>>>>> https://www.cse.buffalo.edu/~knepley/ >>>>>>> <http://www.cse.buffalo.edu/~knepley/> >>>>>>> >>>>>> >>>>> >>>>> -- >>>>> What most experimenters take for granted before they begin their >>>>> experiments is infinitely more interesting than any results to which their >>>>> experiments lead. >>>>> -- Norbert Wiener >>>>> >>>>> https://www.cse.buffalo.edu/~knepley/ >>>>> <http://www.cse.buffalo.edu/~knepley/> >>>>> >>>> >>> >>> -- >>> What most experimenters take for granted before they begin their >>> experiments is infinitely more interesting than any results to which their >>> experiments lead. >>> -- Norbert Wiener >>> >>> https://www.cse.buffalo.edu/~knepley/ >>> <http://www.cse.buffalo.edu/~knepley/> >>> >> > > -- > What most experimenters take for granted before they begin their > experiments is infinitely more interesting than any results to which their > experiments lead. > -- Norbert Wiener > > https://www.cse.buffalo.edu/~knepley/ > <http://www.cse.buffalo.edu/~knepley/> >
