Пример #1
0
Файл: dft.c Проект: Booley/nbis
/*************************************************************************
**************************************************************************
#cat: dft_power_stats - Derives statistics from a set of DFT power vectors.
#cat:           Statistics are computed for all but the lowest frequency
#cat:           wave form, including the Maximum power for each wave form,
#cat:           the direction at which the maximum power occured, and a
#cat:           normalized value for the maximum power.  In addition, the
#cat:           statistics are ranked in descending order based on normalized
#cat:           squared maximum power.  These statistics are fundamental
#cat:           to selecting a dominant direction flow for the current
#cat:           input image block.

   Input:
      powers   - DFT power vectors (N Waves X M Directions) computed for
                 the current image block from which the values in the
                 statistics arrays are derived
      fw       - the beginning of the range of wave form indices from which
                 the statistcs are to derived
      tw       - the ending of the range of wave form indices from which
                 the statistcs are to derived (last index is tw-1)
      ndirs    - number of orientations (directions) at which the DFT
                 analysis was conducted
   Output:
      wis      - list of ranked wave form indicies of the corresponding
                 statistics based on normalized squared maximum power. These
                 indices will be used as indirect addresses when processing
                 the power statistics in descending order of "dominance"
      powmaxs  - array holding the maximum DFT power for each wave form
                 (other than the lowest frequecy)
      powmax_dirs - array to holding the direction corresponding to
                  each maximum power value in powmaxs
      pownorms - array to holding the normalized maximum powers corresponding
                 to each value in powmaxs
   Return Code:
      Zero     - successful completion
      Negative - system error
**************************************************************************/
int dft_power_stats(int *wis, double *powmaxs, int *powmax_dirs,
                     double *pownorms, double **powers,
                     const int fw, const int tw, const int ndirs)
{
   int w, i;
   int ret; /* return code */

   for(w = fw, i = 0; w < tw; w++, i++){
      get_max_norm(&(powmaxs[i]), &(powmax_dirs[i]),
                    &(pownorms[i]), powers[w], ndirs);
   }

   /* Get sorted order of applied DFT waves based on normalized power */
   if((ret = sort_dft_waves(wis, powmaxs, pownorms, tw-fw)))
      return(ret);

   return(0);
}
Пример #2
0
int main(int argc, char* argv[])
{
	if (MPI_Init(&argc, &argv) != MPI_SUCCESS) {
		std::cerr << "Couldn't initialize MPI." << std::endl;
		abort();
	}

	MPI_Comm comm = MPI_COMM_WORLD;

	int rank = 0, comm_size = 0;
	if (MPI_Comm_rank(comm, &rank) != MPI_SUCCESS) {
		std::cerr << "Couldn't obtain MPI rank." << std::endl;
		abort();
	}
	if (MPI_Comm_size(comm, &comm_size) != MPI_SUCCESS) {
		std::cerr << "Couldn't obtain size of MPI communicator." << std::endl;
		abort();
	}


	// intialize Zoltan
	float zoltan_version;
	if (Zoltan_Initialize(argc, argv, &zoltan_version) != ZOLTAN_OK) {
		std::cerr << "Zoltan_Initialize failed." << std::endl;
		abort();
	}

	const unsigned int neighborhood_size = 0;
	const int max_refinement_level = 1;

	std::array<double, 3> old_norm{{
		std::numeric_limits<double>::max(),
		std::numeric_limits<double>::max(),
		std::numeric_limits<double>::max()
	}};
	size_t old_nr_of_cells = 0;
	for (size_t nr_of_cells = 4; nr_of_cells <= 16; nr_of_cells *= 2) {

		dccrg::Dccrg<Cell, dccrg::Cartesian_Geometry> grid;

		const std::array<uint64_t, 3> grid_size{{
			nr_of_cells + 2,
			nr_of_cells + 2,
			nr_of_cells + 2
		}};

		if (
			not grid.initialize(
				grid_size,
				comm,
				"RANDOM",
				neighborhood_size,
				max_refinement_level,
				false, false, false
			)
		) {
			std::cerr << __FILE__ << ":" << __LINE__
				<< ": Couldn't initialize grid."
				<< std::endl;
			abort();
		}

		const std::array<double, 3>
			cell_length{{
				double(5) / (grid_size[0] - 2),
				double(5) / (grid_size[1] - 2),
				double(1) / (grid_size[2] - 2),
			}},
			grid_start{{1, 1, 0}};

		dccrg::Cartesian_Geometry::Parameters geom_params;
		geom_params.start = grid_start;
		geom_params.level_0_cell_length = cell_length;

		if (not grid.set_geometry(geom_params)) {
			std::cerr << __FILE__ << ":" << __LINE__
				<< ": Couldn't set grid geometry."
				<< std::endl;
			abort();
		}

		grid.balance_load();

		for (int i = 0; i < max_refinement_level; i++) {
			for (const auto& cell: grid.get_cells()) {
				const auto center = grid.geometry.get_center(cell);
				if (
					    center[0] > grid_start[0] + cell_length[0] + 5.0*2/4
					and center[0] < grid_start[0] + cell_length[0] + 5.0*4/4
					and center[1] > grid_start[1] + cell_length[1] + 5.0*1/4
					and center[1] < grid_start[1] + cell_length[1] + 5.0*3/4
					and center[2] > grid_start[2] + cell_length[2] + 2.0/4
					and center[2] < grid_start[2] + cell_length[2] + 4.0/4
				) {
					grid.refine_completely(cell);
				}
			}
			grid.stop_refining();
		}

		std::vector<uint64_t> solve_cells;
		for (const auto& cell: grid.get_cells()) {
			auto* const cell_data = grid[cell];
			if (cell_data == nullptr) {
				std::cerr << __FILE__ << ":" << __LINE__ << std::endl;
				abort();
			}

			const auto center = grid.geometry.get_center(cell);
			(*cell_data)[Scalar()] = function(center);

			if (
				    center[0] > grid_start[0] + cell_length[0]
				and center[0] < grid_start[0] + cell_length[0] + 5
				and center[1] > grid_start[1] + cell_length[1]
				and center[1] < grid_start[1] + cell_length[1] + 5
				and center[2] > grid_start[2] + cell_length[2]
				and center[2] < grid_start[2] + cell_length[2] + 1
			) {
				solve_cells.push_back(cell);
			}
		}
		grid.update_copies_of_remote_neighbors();

		pamhd::divergence::get_gradient(
			solve_cells,
			grid,
			[](Cell& cell_data) -> Scalar::data_type& {
				return cell_data[Scalar()];
			},
			[](Cell& cell_data) -> Gradient::data_type& {
				return cell_data[Gradient()];
			}
		);

		const auto norm = get_max_norm(solve_cells, grid);

		for (size_t dim = 0; dim < 3; dim++) {
			if (norm[dim] > old_norm[dim]) {
				if (grid.get_rank() == 0) {
					std::cerr << __FILE__ << ":" << __LINE__
						<< " dim " << dim
						<< ": Norm with " << solve_cells.size()
						<< " cells " << norm[dim]
						<< " is larger than with " << old_nr_of_cells
						<< " cells " << old_norm[dim]
						<< std::endl;
				}
				abort();
			}

			if (old_nr_of_cells > 0) {
				const double order_of_accuracy
					= -log(norm[dim] / old_norm[dim])
					/ log(double(solve_cells.size()) / old_nr_of_cells);

				if (order_of_accuracy < 0.15) {
					if (grid.get_rank() == 0) {
						std::cerr << __FILE__ << ":" << __LINE__
							<< " dim " << dim
							<< ": Order of accuracy from "
							<< old_nr_of_cells << " to " << solve_cells.size()
							<< " is too low: " << order_of_accuracy
							<< std::endl;
					}
					abort();
				}
			}
		}

		old_nr_of_cells = solve_cells.size();
		old_norm = norm;
	}

	MPI_Finalize();

	return EXIT_SUCCESS;
}