コード例 #1
0
ファイル: PETScVector.cpp プロジェクト: norihiro-w/ogs
void PETScVector::gatherLocalVectors( PetscScalar local_array[],
                                      PetscScalar global_array[])
{
    // Collect vectors from processors.
    int size_rank;
    MPI_Comm_size(PETSC_COMM_WORLD, &size_rank);

    // number of elements to be sent for each rank
    std::vector<PetscInt>  i_cnt(size_rank);

    MPI_Allgather(&_size_loc, 1, MPI_INT, &i_cnt[0], 1, MPI_INT, PETSC_COMM_WORLD);

    // collect local array
    PetscInt offset = 0;
    // offset in the receive vector of the data from each rank
    std::vector<PetscInt>  i_disp(size_rank);
    for(PetscInt i=0; i<size_rank; i++)
    {
        i_disp[i] = offset;
        offset += i_cnt[i];
    }

    MPI_Allgatherv(local_array, _size_loc, MPI_DOUBLE,
                   global_array, &i_cnt[0], &i_disp[0], MPI_DOUBLE, PETSC_COMM_WORLD);

}
コード例 #2
0
ファイル: dense_encoding_map.hpp プロジェクト: oakad/ucpf
	std::ostream &dump(std::ostream &os) const
	{
		std::size_t i_cnt(0);
		for (std::size_t c(0); c < size(); ++c) {
			std::size_t idx(std::get<0>(tup_items_alloc)[c * 2]);
			std::size_t val(
				std::get<0>(tup_items_alloc)[c * 2 + 1]
			);
			if ((c == idx) && (c == val)) {
				++i_cnt;
				continue;
			}

			if (i_cnt) {
				os << "identity (" << i_cnt << " positions)\n";
				i_cnt = 0;
			}
			os << c << ": " << idx << ", " << val << '\n';
		}
		if (i_cnt)
			os << "identity (" << i_cnt << " positions)\n";

		return os;
	}