@@ -532,7 +532,10 @@ PetscErrorCode sp_evaluate_surface_processes_2d_diffusion(PetscReal dt)
532532 PetscInt seq_surface_size;
533533 PetscInt p;
534534 PetscInt bs;
535- PetscReal *seq_array;
535+ PetscReal *seq_array = NULL ;
536+ PetscReal *seq_array_copy = NULL ;
537+ PetscReal *seq_array_aux = NULL ;
538+ PetscReal *array = NULL ;
536539 PetscReal sp_dt;
537540 PetscInt t;
538541 PetscInt j;
@@ -542,7 +545,6 @@ PetscErrorCode sp_evaluate_surface_processes_2d_diffusion(PetscReal dt)
542545 PetscScalar *z;
543546 PetscInt si;
544547 PetscInt nlocal;
545- PetscReal *array;
546548 PetscInt n;
547549
548550 PetscFunctionBeginUser;
@@ -600,22 +602,29 @@ PetscErrorCode sp_evaluate_surface_processes_2d_diffusion(PetscReal dt)
600602 ierr = MPI_Bcast (&seq_surface_size, 1 , MPI_INT, 0 , PETSC_COMM_WORLD); CHKERRQ (ierr);
601603
602604 if (rank) {
603- ierr = PetscCalloc1 (seq_surface_size, &seq_array); CHKERRQ (ierr);
605+ ierr = PetscCalloc1 (seq_surface_size, &seq_array_copy); CHKERRQ (ierr);
606+ ierr = MPI_Bcast (seq_array_copy, seq_surface_size, MPIU_SCALAR, 0 , PETSC_COMM_WORLD); CHKERRQ (ierr);
607+ seq_array_aux = seq_array_copy;
608+ } else {
609+ ierr = MPI_Bcast (seq_array, seq_surface_size, MPIU_SCALAR, 0 , PETSC_COMM_WORLD);
610+ seq_array_aux = seq_array;
604611 }
605- ierr = MPI_Bcast (seq_array, seq_surface_size, MPIU_SCALAR, 0 , PETSC_COMM_WORLD);
606612
607613 ierr = DMDAGetCorners (da_Veloc, &si, NULL , NULL , NULL , NULL , NULL ); CHKERRQ (ierr);
608614 ierr = DMSwarmGetLocalSize (dms_s, &nlocal); CHKERRQ (ierr);
609615 ierr = DMSwarmGetField (dms_s, DMSwarmPICField_coor, &bs, NULL , (void **)&array); CHKERRQ (ierr);
610616
611617 for (p = 0 ; p < nlocal; p++) {
612- array[2 *p] = seq_array [si*dms_s_ppe*2 +2 *p];
613- array[2 *p+1 ] = seq_array [si*dms_s_ppe*2 +2 *p+1 ];
618+ array[2 *p] = seq_array_aux [si*dms_s_ppe*2 +2 *p];
619+ array[2 *p+1 ] = seq_array_aux [si*dms_s_ppe*2 +2 *p+1 ];
614620 }
615621
616622 ierr = DMSwarmRestoreField (dms_s, DMSwarmPICField_coor, &bs, NULL , (void **)&array); CHKERRQ (ierr);
617623 ierr = VecRestoreArray (seq_surface, &seq_array); CHKERRQ (ierr);
618624 ierr = VecDestroy (&seq_surface); CHKERRQ (ierr);
625+ if (rank) {
626+ ierr = PetscFree (seq_array_copy); CHKERRQ (ierr);
627+ }
619628
620629 PetscFunctionReturn (0 );
621630}
@@ -677,8 +686,10 @@ PetscErrorCode sp_evaluate_surface_processes_2d_sedimentation_rate_limited(Petsc
677686 Vec global_surface;
678687 Vec seq_surface;
679688 VecScatter ctx;
680- PetscReal *seq_array;
681- PetscReal *array;
689+ PetscReal *seq_array = NULL ;
690+ PetscReal *seq_array_copy = NULL ;
691+ PetscReal *seq_array_aux = NULL ;
692+ PetscReal *array = NULL ;
682693
683694 ierr = DMSwarmCreateGlobalVectorFromField (dms_s, DMSwarmPICField_coor, &global_surface); CHKERRQ (ierr);
684695 ierr = VecScatterCreateToZero (global_surface, &ctx, &seq_surface); CHKERRQ (ierr);
@@ -828,23 +839,29 @@ PetscErrorCode sp_evaluate_surface_processes_2d_sedimentation_rate_limited(Petsc
828839 ierr = MPI_Bcast (&seq_surface_size, 1 , MPI_INT, 0 , PETSC_COMM_WORLD); CHKERRQ (ierr);
829840
830841 if (rank) {
831- ierr = PetscCalloc1 (seq_surface_size, &seq_array); CHKERRQ (ierr);
842+ ierr = PetscCalloc1 (seq_surface_size, &seq_array_copy); CHKERRQ (ierr);
843+ ierr = MPI_Bcast (seq_array_copy, seq_surface_size, MPIU_SCALAR, 0 , PETSC_COMM_WORLD); CHKERRQ (ierr);
844+ seq_array_aux = seq_array_copy;
845+ } else {
846+ ierr = MPI_Bcast (seq_array, seq_surface_size, MPIU_SCALAR, 0 , PETSC_COMM_WORLD);
847+ seq_array_aux = seq_array;
832848 }
833- ierr = MPI_Bcast (seq_array, seq_surface_size, MPIU_SCALAR, 0 , PETSC_COMM_WORLD);
834849
835850 ierr = DMDAGetCorners (da_Veloc, &si, NULL , NULL , NULL , NULL , NULL ); CHKERRQ (ierr);
836851 ierr = DMSwarmGetLocalSize (dms_s, &nlocal); CHKERRQ (ierr);
837852 ierr = DMSwarmGetField (dms_s, DMSwarmPICField_coor, &bs, NULL , (void **)&array); CHKERRQ (ierr);
838853
839854 for (j = 0 ; j < nlocal; j++) {
840- array[2 *j] = seq_array [si*dms_s_ppe*2 +2 *j];
841- array[2 *j+1 ] = seq_array [si*dms_s_ppe*2 +2 *j+1 ];
855+ array[2 *j] = seq_array_aux [si*dms_s_ppe*2 +2 *j];
856+ array[2 *j+1 ] = seq_array_aux [si*dms_s_ppe*2 +2 *j+1 ];
842857 }
843858
844859 ierr = DMSwarmRestoreField (dms_s, DMSwarmPICField_coor, &bs, NULL , (void **)&array); CHKERRQ (ierr);
845860 ierr = VecRestoreArray (seq_surface, &seq_array); CHKERRQ (ierr);
846861 ierr = VecDestroy (&seq_surface); CHKERRQ (ierr);
847-
862+ if (rank) {
863+ ierr = PetscFree (seq_array_copy); CHKERRQ (ierr);
864+ }
848865
849866 PetscFunctionReturn (0 );
850867}
0 commit comments