Commit 9daba5af authored by Thomas Ponweiser's avatar Thomas Ponweiser
Browse files

moved cartesian communicator creation to world.c

parent ac7624f3
......@@ -19,11 +19,10 @@ The code sample is structured as follows:
* `configuration.c`, `configuration.h`: Command line parsing and basic logging facilities.
* `io.c`, `io.h`: Collective I/O of the cellular automaton state.
* `main.c`: The main program
* `broadcast_configuration`: Broadcasting the parsed command line arguments.
* `create_cart_comm`: Creation of the MPI Cartesian communicator.
* `mpitypes.c`, `mpitypes.h`: Creation of MPI datatypes.
* `simulation.c`, `simulation.h`: Demonstration of 6 approaches for implementing a Wireworld cellular automaton.
* `world.c`, `world.h`: Initialization of the cellular automaton and associated MPI objects.
* `create_cart_comm`: Creation of the MPI Cartesian communicator.
* `world_init`: Domain decomposition and buffer allocation.
* `world_init_io_type`: Creation of the MPI subarray datatype for I/O.
* `world_init_neighborhood`: Identification of neighboring processes, creation of MPI graph communicator.
......
......@@ -13,8 +13,6 @@ 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);
......@@ -94,40 +92,13 @@ void read_input(const conf_t *c, world_t *world) {
header_length, global_sizes[0], global_sizes[1]
);
// Initialize cells (determine local tile, allocate memory)
create_cart_comm(c, &cart_comm);
world_init(world, cart_comm, global_sizes, c);
MPI_Comm_free(&cart_comm);
world_init(world, global_sizes, c);
// 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 int n_it = c->n_iterations;
......
......@@ -2,6 +2,7 @@
#include "world.h"
void create_cart_comm(const conf_t *c, MPI_Comm *cart_comm);
void world_init_io_type(world_t *world);
void world_free_io_type(world_t *world);
......@@ -12,13 +13,42 @@ void world_free_neighborhood(world_t *world);
void world_init_persistent_requests(world_t *world, const conf_t *c);
void world_free_persistent_requests(world_t *world);
void world_init(world_t *world, MPI_Comm cart_comm, size_t *global_size, const conf_t *c)
// --------------------------------------------------------------------------
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 world_init(world_t *world, size_t *global_size, const conf_t *c)
{
int dim, lo, hi;
int nprocs[2], periods[2], proc_coord[2];
char *buffer;
size_t storage_size;
MPI_Comm cart_comm;
create_cart_comm(c, &cart_comm);
MPI_Cart_get(cart_comm, 2, nprocs, periods, proc_coord);
for(dim = 0; dim < 2; dim++) {
......@@ -40,6 +70,8 @@ void world_init(world_t *world, MPI_Comm cart_comm, size_t *global_size, const c
world_init_neighborhood(world, cart_comm, nprocs, proc_coord, c);
world_init_persistent_requests(world, c);
MPI_Comm_free(&cart_comm);
if(trace_enabled(c)) {
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
......
......@@ -32,7 +32,7 @@ typedef struct
transfer_t transfer;
} world_t;
void world_init(world_t *world, MPI_Comm cart_comm, size_t *global_size, const conf_t *c);
void world_init(world_t *world, size_t *global_size, const conf_t *c);
size_t world_get_storage_size(const world_t *world);
......
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