Gideon Simpson <[email protected]> writes: > I'm migrating some monte carlo code over to petsc, where the realizations > will be done serially, but distributed across the cluster. I'm inclined to > involve petsc in this for its data management, and had a couple of questions. > > If I plant to store the (scalar) results of the monte carlo simulations in a > Petsc vector v, what is the recommended method for putting the results into > this vector? Currently, I have implemented: > > VecGetOwnershipRange(sim_data, &local_start, &local_end); > > VecGetArray(sim_data,& sim_data_local); > k=0; > > for(i=local_start;i<local_end;i++){ > > sim_result = mc_sim_cod(mc_args); > > sim_data_local[k] = sim_result; > k++; > > } > VecRestoreArray(sim_data, & sim_data_local); > > Is this a *good* solution, or should I be using SetValue routines?
The above is fine. > Also, I have MC simulations which, instead of returning a single > scalar, return some n-dimensional array of real values. In that case, > I was thinking to make sim_data a petsc matrix. If each result was > n-dimensional, how would I initialize the matrix to hold M > realizations of this n dimensional matrix? ensuring that each set of > n was contiguous on the local machine? Mat is really for linear operators, not a container for data that you want to interpret as 2-dimensional. DMDA can do the latter, especially if you want to distribute. > Alternatively, this could be an n*M vector, but again, I'd need to > ensure each chunk of n was located on the same machine? Just set the local sizes of the Vec such that the entire subset is local. See the middle argument to VecSetSizes(). > I presume here, I would use SetValue routines to insert each chunk of > data. You could, but writing directly into the array is also fine. > Also, this may have to do with it being the newest matlab, 2013b, but when I > try to load petsc vectors i receive the following error: > > Error using load > Number of columns on line 2 of ASCII file sim_data.out > must be the same as previous lines. > > where I constructed the sim_data.out file using the lines: > > PetscViewerASCIIOpen(PETSC_COMM_WORLD, "sim_data.out", &output_viewer); > PetscViewerSetFormat(output_viewer, PETSC_VIEWER_ASCII_MATLAB); > VecView(sim_data,output_viewer); > PetscViewerDestroy(&output_viewer); > > Looking at the ascii file, it looks fine. Did MATLAB change their ASCII format? Anyway, it is much better to write binary output and read with PetscBinaryRead (bin/matlab/PetscBinaryRead.m).
pgp2zbwILGMRz.pgp
Description: PGP signature
