[petsc-users] petsc vector management for monte carlo

Jed Brown jedbrown at mcs.anl.gov
Sat Nov 30 15:12:42 CST 2013


Gideon Simpson <gideon.simpson at gmail.com> writes:

> If each realization generated a size n output, is there something slicker than this:
>
> VecGetOwnershipRange(sim_data, &local_start, &local_end);
>
> VecGetArray(sim_data,& sim_data_local);
> k=0;
>
> m_local = (local_end - local_start-1)/n;

local_end is one past the last owned entry.

> for(i=0;i< m_local;i++){
>
>    mc_sim_cod(mc_args, &sim_result);
>
>    for(k = 0;k<n;k++){
>
>       sim_data_local[i * n + k] = sim_result[k];
>    }
>
>  }

You can drop the result directly into the array:

  for (i=local_start; i<local_end; i+=n) {
    mc_sim_cod(mc_args, sim_data_local+(i-local_start));
  }

>> Did MATLAB change their ASCII format?
>
> Here's a quick test on 2013b:
> v = linspace(0,1,5);
> save('test.out', 'v', '-ascii');
>
> test.out looks like:
>    0.0000000e+00   2.5000000e-01   5.0000000e-01   7.5000000e-01   1.0000000e+00

ASCII_MATLAB output is meant to be sourced:

v = [
0.0000000e+00
2.5000000e-01
5.0000000e-01
7.5000000e-01
1.0000000e+00
];

>> Anyway, it is much better to write binary output and read with
>> PetscBinaryRead (bin/matlab/PetscBinaryRead.m).

But seriously, use binary.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20131130/71215220/attachment-0001.pgp>


More information about the petsc-users mailing list