Beispiel #1
0
	void fill_matrix(int rank, Distribution &ds, Distribution &block_ds) {

		// set B columns
		int n_cols_B=block_ds.size();
		std::vector<PetscInt> b_cols(n_cols_B);
		for( unsigned int p=0;p<block_ds.np();p++)
			for (unsigned int j=block_ds.begin(p); j<block_ds.end(p); j++) {
				//int proc=block_ds.get_proc(j);
				b_cols[j]=ds.end(p)+j;
			}

		// create block A of matrix
		int local_idx=0;
		for (unsigned int i = block_ds.begin(); i < block_ds.end(); i++) {
			// make random block values
			std::vector<PetscScalar> a_vals(block_size * block_size, 0);
			for (unsigned int j=0; j<block_size; j++)
				a_vals[ j + j*block_size ]= (rank + 2);

			// set rows and columns indices
			std::vector<PetscInt> a_rows(block_size);
			for (unsigned int j=0; j<block_size; j++) {
				a_rows[j]=ds.begin() + block_ds.begin() + local_idx;
				local_idx++;
			}
			mat_set_values(block_size, &a_rows[0], block_size, &a_rows[0], &a_vals[0]);

			// set B values
			std::vector<PetscScalar> b_vals(block_size*n_cols_B);
			for (int j=0; j<block_size*n_cols_B; j++)
				b_vals[j] = 1;

			// set C values
			std::vector<PetscScalar> c_vals(n_cols_B);
			for (int j=0; j<n_cols_B; j++)
				c_vals[j] = 0;

			// must iterate per rows to get correct transpose
			for(unsigned int row=0; row<block_size;row++) {
				mat_set_values(1, &a_rows[row], 1, &b_cols[rank], &b_vals[row*n_cols_B]);
				mat_set_values(1, &b_cols[rank],1, &a_rows[row], &b_vals[row*n_cols_B]);
			}

			mat_set_values(1, &b_cols[rank], 1, &b_cols[rank], &c_vals[rank]);

		}
	}
Beispiel #2
0
void print(Distribution values){
	for (Distribution::iterator it=values.begin();it!=values.end();it++){
		cout << "(" << it->first.first << "," << it->first.second << "):" << endl;
		cout << "vector1:" << endl;
		int size1 = it->second.first.size();
		for (int i=0;i<size1;i++){cout << it->second.first[i] << endl;}
		cout << "vector2:" << endl;
		int size2 = it->second.second.size();
		for (int i=0;i<size2;i++){cout << it->second.second[i] << endl;}
	}
}