Commit 2b4b39de authored by Johannes Blaschke's avatar Johannes Blaschke
Browse files

clean up in main.c

parent 43d86f9c
......@@ -415,8 +415,61 @@ void run_n_timesteps(int n, world_state* world, int ext_control)
//all_cpus_print_active_and_inactive_squirmers(get_squirmers(world), get_nsquirmers(world), "Squirmers[end]");
}
int
main(int argc, char * argv[])
void main_support__print_core_domains(FILE * file_dest){
// Collects (MPI_Gather) core domains and prints them to FILE * file_dest
// MPI-lib, malloc, free
// **** PREFLIGHT **************************************************************************************************************************************
// only integer-part of comain limits is sent (the rest is gridshift anyway)
int domain_min_x = (int) cpu.upleftlimit.x;
int domain_min_y = (int) cpu.upleftlimit.y;
int domain_min_z = (int) cpu.upleftlimit.z;
int domain_max_x = (int) cpu.downrightlimit.x;
int domain_max_y = (int) cpu.downrightlimit.y;
int domain_max_z = (int) cpu.downrightlimit.z;
// allocate buffers
int * rec_min_x = malloc(config.ncpus*sizeof(int));
int * rec_min_y = malloc(config.ncpus*sizeof(int));
int * rec_min_z = malloc(config.ncpus*sizeof(int));
int * rec_max_x = malloc(config.ncpus*sizeof(int));
int * rec_max_y = malloc(config.ncpus*sizeof(int));
int * rec_max_z = malloc(config.ncpus*sizeof(int));
// ***** MPI-Gather data to core 0 *********************************************************************************************************************
MPI_Gather(& domain_min_x, 1, MPI_INT, rec_min_x, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Gather(& domain_min_y, 1, MPI_INT, rec_min_y, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Gather(& domain_min_z, 1, MPI_INT, rec_min_z, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Gather(& domain_max_x, 1, MPI_INT, rec_max_x, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Gather(& domain_max_y, 1, MPI_INT, rec_max_y, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Gather(& domain_max_z, 1, MPI_INT, rec_max_z, 1, MPI_INT, 0, MPI_COMM_WORLD);
// ***** PRINT collected data to core 0's file buffer FILE * file_dest *********************************************************************************
if (cpu.rank == 0){
fprintf(file_dest, "INIT: cores fully initialized.\n ** Core domains ([min_x, min_y, min_z]/upleftlimit, [max_x, max_y, max_z]/downrightlimit):\n");
for(int i=0; i<config.ncpus; i++){
fprintf(file_dest, " * cpu: %d, : [%d, %d, %d], [%d, %d, %d]\n", i, rec_min_x[i], rec_min_y[i], rec_min_z[i], rec_max_x[i], rec_max_y[i], rec_max_z[i]);
}
fprintf(file_dest, "\n");
}
// ***** POSTFLIGHT ************************************************************************************************************************************
// free allocated buffers
free(rec_min_x);
free(rec_min_y);
free(rec_min_z);
free(rec_max_x);
free(rec_max_y);
free(rec_max_z);
}
int main(int argc, char * argv[])
{
signal(SIGSEGV, &printBacktrace);
signal(SIGABRT, &printBacktrace);
......@@ -460,37 +513,7 @@ main(int argc, char * argv[])
MPI_Barrier(MPI_COMM_WORLD);
int domain_min_x = (int) cpu.upleftlimit.x;
int domain_min_y = (int) cpu.upleftlimit.y;
int domain_min_z = (int) cpu.upleftlimit.z;
int domain_max_x = (int) cpu.downrightlimit.x;
int domain_max_y = (int) cpu.downrightlimit.y;
int domain_max_z = (int) cpu.downrightlimit.z;
int * rec_min_x = malloc(config.ncpus*sizeof(int));
int * rec_min_y = malloc(config.ncpus*sizeof(int));
int * rec_min_z = malloc(config.ncpus*sizeof(int));
int * rec_max_x = malloc(config.ncpus*sizeof(int));
int * rec_max_y = malloc(config.ncpus*sizeof(int));
int * rec_max_z = malloc(config.ncpus*sizeof(int));
MPI_Gather(& domain_min_x, 1, MPI_INT, rec_min_x, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Gather(& domain_min_y, 1, MPI_INT, rec_min_y, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Gather(& domain_min_z, 1, MPI_INT, rec_min_z, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Gather(& domain_max_x, 1, MPI_INT, rec_max_x, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Gather(& domain_max_y, 1, MPI_INT, rec_max_y, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Gather(& domain_max_z, 1, MPI_INT, rec_max_z, 1, MPI_INT, 0, MPI_COMM_WORLD);
if (cpu.rank == 0){
fprintf(stdout, "INIT: cores fully initialized.\n ** Core domains ([min_x, min_y, min_z]/upleftlimit, [max_x, max_y, max_z]/downrightlimit):\n");
for(int i=0; i<config.ncpus; i++){
fprintf(stdout, " * cpu: %d, : [%d, %d, %d], [%d, %d, %d]\n", i, rec_min_x[i], rec_min_y[i], rec_min_z[i], rec_max_x[i], rec_max_y[i], rec_max_z[i]);
}
fprintf(stdout, "\n");
}
main_support__print_core_domains(stdout);
// fprintf(stdout, "core: %d down right = %f %f %f, up left = %f %f %f\n", cpu.rank, cpu.downrightlimit.x, cpu.downrightlimit.y, cpu.downrightlimit.z, cpu.upleftlimit.x, cpu.upleftlimit.y, cpu.upleftlimit.z);
......@@ -506,7 +529,7 @@ main(int argc, char * argv[])
run_n_timesteps(config.ntimesteps, & world, 0);
STOP(entire_simulation);
print_durations_to_file();
free_memory(&world);
free_memory(& world);
}
else printf("Something went wrong in the initialization, aborting \n \n");
}
......
Markdown is supported
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