Dear Matthew, I came up with a workaround for the problem. I duplicate the vector and use the duplicated copy to read the information from the hdf5 file. Then I swap both vectors and delete the copy. If I invoke VecView outside of the function, the value has been modified properly. However, this solution seems a little bit “ugly”. I share it just in case someone is facing a similar problem or it can help to understand what is going wrong with my previous implementation.
Best, Miguel Vec stdv_q; PetscCall(DMSwarmCreateGlobalVectorFromField(Simulation->atomistic_data, "stdv-q", &stdv_q)); Vec stdv_q_hdf5; PetscCall(VecDuplicate(stdv_q, &stdv_q_hdf5)); PetscCall(PetscObjectSetName((PetscObject)stdv_q_hdf5, "DMSwarmSharedField_stdv-q")); PetscCall(VecLoad(stdv_q_hdf5, viewer_hdf5)); PetscCall(VecSwap(stdv_q, stdv_q_hdf5)); PetscCall(VecDestroy(&stdv_q_hdf5)); PetscCall(DMSwarmDestroyGlobalVectorFromField(Simulation->atomistic_data, "stdv-q", &stdv_q)); On 1 Apr 2024, at 17:13, Miguel Molinos <[email protected]> wrote: Dear Matthew, Thank you for your suggestion. I tried to update the vector with the information coming from the hdf5 file inside the main function. Then I print the vector two times (see the lines below), the first time it has the correct data. However, the second time, it has the same values like I never updated it with VecLoad. It is an alternative way of initialise a vector coming from DMSWarm with previously stored information (keeping the parallel structure)? Miguel //! Load Hdf5 viewer PetscViewer viewer_hdf5; REQUIRE_NOTHROW(PetscViewerHDF5Open(MPI_COMM_WORLD, Output_hdf5_file, FILE_MODE_READ, &viewer_hdf5)); REQUIRE_NOTHROW(PetscViewerHDF5PushTimestepping(viewer_hdf5)); //! Load the vector and fill it with the information from the .hdf5 file Vec stdv_q; REQUIRE_NOTHROW(DMSwarmCreateGlobalVectorFromField( Simulation.atomistic_data, "stdv-q", &stdv_q)); REQUIRE_NOTHROW(PetscViewerHDF5PushGroup(viewer_hdf5, "/particle_fields")); REQUIRE_NOTHROW(VecLoad(stdv_q, viewer_hdf5)); REQUIRE_NOTHROW(VecView(stdv_q, PETSC_VIEWER_STDOUT_WORLD)); REQUIRE_NOTHROW(PetscViewerHDF5PopGroup(viewer_hdf5)); REQUIRE_NOTHROW(DMSwarmDestroyGlobalVectorFromField( Simulation.atomistic_data, "stdv-q", &stdv_q)); //! Destoy HDF5 context REQUIRE_NOTHROW(PetscViewerDestroy(&viewer_hdf5)); //! Load the vector again and print REQUIRE_NOTHROW(DMSwarmCreateGlobalVectorFromField( Simulation.atomistic_data, "stdv-q", &stdv_q)); REQUIRE_NOTHROW(VecView(stdv_q, PETSC_VIEWER_STDOUT_WORLD)); REQUIRE_NOTHROW(DMSwarmDestroyGlobalVectorFromField( Simulation.atomistic_data, "stdv-q", &stdv_q)); Best, Miguel Miguel Molinos Investigador postdoctoral Juan de la Cierva Dpto. Mecánica de Medios Continuos y Teoría de Estructuras - ETSI Universidad de Sevilla Camino de los descubrimientos, s/n 41092 Sevilla <us_logo.jpg> https://urldefense.us/v3/__http://www.us.es__;!!G_uCfscf7eWS!dcgV4Ks7of5UCrBcwXoQzq1ZP06FAF8IaHAwnyo5mL5uiBMiKj2mxO7W6odOpn8LRgla6ehj-QCjHK2MbBf_1Q$ Este correo electrónico y, en su caso, cualquier fichero anexo al mismo, contiene información de carácter confidencial exclusivamente dirigida a su destinatario o destinatarios. Si no es UD. el destinatario del mensaje, le ruego lo destruya sin hacer copia digital o física, comunicando al emisor por esta misma vía la recepción del presente mensaje. Gracias On 1 Apr 2024, at 16:28, Matthew Knepley <[email protected]> wrote: >From the description, my guess is that this is pointer confusion. The vector >inside the function is different from the vector outside the function.
