Commit 67ce0be8 authored by Thomas Ponweiser's avatar Thomas Ponweiser
Browse files

improved console output

parent ed0da381
......@@ -152,7 +152,12 @@ int info_enabled(const conf_t *c)
int debug_enabled(const conf_t *c)
{
return log_enabled(c, DEBUG);
static int rank = -1;
if(rank < 0) {
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
}
return log_enabled(c, DEBUG) && rank == 0;
}
int trace_enabled(const conf_t *c)
......
......@@ -13,6 +13,8 @@ void broadcast_configuration(conf_t *c);
void read_input(const conf_t *c, world_t *world);
void create_cart_comm(const conf_t *c, MPI_Comm *cart_comm);
void iterate(const conf_t *c, world_t *world);
void print_avg_timings(const conf_t *c, double total_time, double sim_time, double io_time);
......@@ -67,8 +69,6 @@ void broadcast_configuration(conf_t *c) {
void read_input(const conf_t *c, world_t *world) {
int rank;
const int periods[2] = {0}; // non-periodic boundaries
const int allow_reorder = 1;
MPI_Comm cart_comm;
char input_filename[FILE_NAME_SZ];
......@@ -88,31 +88,50 @@ void read_input(const conf_t *c, world_t *world) {
// Read header
file_read_header(file, global_sizes, &header_length);
if(info_enabled(c)) printf(
if(debug_enabled(c)) printf(
"Read header (%ld characters).\n"
"Global size: %ld x %ld\n\n",
header_length, global_sizes[0], global_sizes[1]
);
// Initialize cells (determine local tile, allocate memory)
MPI_Cart_create(MPI_COMM_WORLD, 2, c->nprocs, periods, allow_reorder, &cart_comm);
create_cart_comm(c, &cart_comm);
world_init(world, cart_comm, global_sizes, c);
MPI_Comm_free(&cart_comm);
if(debug_enabled(c)) printf(
"%03d: Local tile: [%ld %ld) x [%ld %ld)\n", rank,
world->local_start[0], world->local_start[0]+world->local_size[0],
world->local_start[1], world->local_start[1]+world->local_size[1]
);
// Collectively read cell data
file_read_world(file, world, header_length);
MPI_File_close(&file);
}
void create_cart_comm(const conf_t *c, MPI_Comm *cart_comm)
{
const int periods[] = {0, 0}; // non-periodic boundaries
const int allow_reorder = 1;
int comm_world_rank, new_rank;
int local_ranks_different, ranks_reordered;
if(debug_enabled(c)) printf("Creating Cartesian communicator...\n");
MPI_Cart_create(MPI_COMM_WORLD, 2, c->nprocs, periods, allow_reorder, cart_comm);
MPI_Comm_rank(MPI_COMM_WORLD, &comm_world_rank);
MPI_Comm_rank(*cart_comm, &new_rank);
local_ranks_different = comm_world_rank != new_rank;
MPI_Allreduce(
&local_ranks_different, &ranks_reordered, 1, MPI_INT,
MPI_LOR, MPI_COMM_WORLD
);
if(debug_enabled(c)) printf(
"INFO: MPI reordered ranks: %s\n", ranks_reordered ? "YES" : "NO"
);
}
void iterate(const conf_t *c, world_t *world)
{
const size_t n_it = c->n_iterations;
const size_t n_gen = c->n_generations_per_iteration;
const int n_it = c->n_iterations;
const long n_gen = c->n_generations_per_iteration;
size_t i, g;
double total_time, sim_time = 0, io_time = 0;
......
......@@ -20,9 +20,9 @@ void mpitype_conf_init(MPI_Datatype *new_type)
MPI_Get_address(&dummy.CONF_T_FIRST_LONG_MEMBER, &displacements[1]);
MPI_Get_address(&dummy.CONF_T_FIRST_CHAR_MEMBER, &displacements[2]);
for(i = 0; i < 2; i++) displacements[i] -= base;
for(i = 0; i < 3; i++) displacements[i] -= base;
MPI_Type_create_struct(2, blocklengths, displacements, types, new_type);
MPI_Type_create_struct(3, blocklengths, displacements, types, new_type);
MPI_Type_commit(new_type);
}
......
......@@ -39,6 +39,16 @@ void world_init(world_t *world, MPI_Comm cart_comm, size_t *global_size, const c
world_init_io_type(world);
world_init_neighborhood(world, cart_comm, nprocs, proc_coord, c);
world_init_persistent_requests(world, c);
if(trace_enabled(c)) {
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
printf(
"%03d: Local tile: [%ld %ld) x [%ld %ld)\n", rank,
world->local_start[0], world->local_start[0]+world->local_size[0],
world->local_start[1], world->local_start[1]+world->local_size[1]
);
}
}
void world_free(world_t *world)
......@@ -143,6 +153,8 @@ void world_init_neighborhood(world_t *world, MPI_Comm cart_comm, int nprocs[], i
if(c->transmission_mode == SPARSE_COLLECTIVE) {
const int allow_reorder = 0;
if(debug_enabled(c)) printf("Creating MPI distributed graph communicator...\n");
MPI_Dist_graph_create_adjacent(cart_comm,
n, neighbor_ranks, weights,
n, neighbor_ranks, weights,
......@@ -182,6 +194,8 @@ void world_init_persistent_requests(world_t *world, const conf_t *c)
MPI_Comm comm = world->transfer.comm;
if(debug_enabled(c)) printf("Initializing persistent requests...\n");
for(i = 0; i < n_neighbors; i++) {
MPI_Send_init(
world->cells_prev, 1, send_types[i], neighbor_ranks[i],
......@@ -215,7 +229,7 @@ void world_free_persistent_requests(world_t *world)
size_t world_get_storage_size(const world_t *world)
{
const size_t nx = world->local_size[0],
const size_t nx = world->local_size[0],
ny = world->local_size[1];
return (nx+2)*(ny+2)*sizeof(char);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment