Commit b3eedfc5 authored by Björn Fischer's avatar Björn Fischer

refactor first init part

parent 184196c8
8 4
8 4
0.0000000000 0.0000000000
0.1428571429 0.3333333333
0.2857142857 0.6666666667
0.4285714286
0.5714285714
0.7142857143
0.8571428571
1.0000000000 1.0000000000
0.1428571429 0.3333333333
0.0000182857 0.0000106667
0.0000182857 0.0000213333
0.0000274286 0.6666666667
0.0000365714
0.0000457143
0.0001097143
0.8571428571
0.2857142857 0.6666666667
0.0000182857 0.0000213333
0.0000000000 0.0000106667
0.0000000000 0.3333333333
0.0000000000
0.0000000000
0.0000457143
0.7142857143
0.4285714286
0.0000274286
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000365714
0.5714285714
0.5714285714
0.0000365714
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000274286
0.4285714286
0.7142857143
0.0000457143
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000182857
0.2857142857
0.8571428571
0.0001097143
0.0000457143
0.0000365714
0.0000274286
0.0000182857
0.0000182857
0.1428571429
1.0000000000 1.0000000000
0.8571428571 0.6666666667
0.7142857143 0.3333333333
0.5714285714
0.4285714286
0.2857142857
0.1428571429
0.0000000000 0.0000000000
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
void process_args(int argc, char **argv, int *m, int *n, double *eps, double *delta_t) { void Process_Args(int argc, char **argv, int *m, int *n, double *eps, double *delta_t) {
if ((argc < 3) || (argc > 5)) { if ((argc < 3) || (argc > 5)) {
fprintf(stderr, "Usage: heat <m> <n> [<epsilon> [delta_t]]!\n\n"); fprintf(stderr, "Usage: heat <m> <n> [<epsilon> [delta_t]]!\n\n");
fprintf(stderr, " <m> -- X-Size of matrix\n"); fprintf(stderr, " <m> -- X-Size of matrix\n");
......
No preview for this file type
...@@ -17,15 +17,18 @@ int main(int argc, char **argv) ...@@ -17,15 +17,18 @@ int main(int argc, char **argv)
{ {
MPI_Init(&argc, &argv); MPI_Init(&argc, &argv);
int m, n; int m, n;
double **root_field; double **root_field; // complete field owned by root
double **partial_field; double **partial_field; // partial field where process works on
double start, end; double start, end;
t_process_info pi; t_process_info pi;
t_process_info *infos; t_process_info *infos;
int pro_per_dim[2];
int cell_per_pro[2];
MPI_Comm cart_comm;
Create_MPI_Type_t_process_info(&MPI_process_info); Create_MPI_Type_t_process_info(&MPI_process_info);
process_args(argc, argv, &m, &n, &eps, &delta_t); Process_Args(argc, argv, &m, &n, &eps, &delta_t);
int rank, num_p; int rank, num_p;
if(MPI_Comm_rank(MPI_COMM_WORLD, &rank)) { if(MPI_Comm_rank(MPI_COMM_WORLD, &rank)) {
...@@ -33,11 +36,6 @@ int main(int argc, char **argv) ...@@ -33,11 +36,6 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
if(MPI_Comm_size(MPI_COMM_WORLD, &num_p)) {
fprintf(stderr, "Cannot fetch size of cluster\n");
exit(1);
}
if(rank == 0) { if(rank == 0) {
root_field = New_Matrix(m, n); root_field = New_Matrix(m, n);
if (root_field == NULL) { if (root_field == NULL) {
...@@ -46,59 +44,12 @@ int main(int argc, char **argv) ...@@ -46,59 +44,12 @@ int main(int argc, char **argv)
} }
} }
if(rank == 0) { // optimize cart cluster
printf("number of processes: %d\n", num_p); Optimize_Cart_Cluster(m, n, MPI_COMM_WORLD, rank, pro_per_dim, cell_per_pro);
}
int pro_per_dim[2]; cart_comm = Create_MPI_Cart_Cluster(MPI_COMM_WORLD, rank, pro_per_dim);
float temp_f,temp_g;
temp_g = sqrt((float)(num_p*m)/n);
temp_f = num_p/temp_g;
temp_g = floor(temp_g);
temp_f = floor(temp_f);
pro_per_dim[0] = (int)temp_f;
pro_per_dim[1] = (int)temp_g;
int m_per_pro, n_per_pro;
m_per_pro = ceil(m/(float)pro_per_dim[1]);
n_per_pro = ceil(n/(float)pro_per_dim[0]);
if(rank==0) {
printf("dim0: %d dim1: %d\n", pro_per_dim[0], pro_per_dim[1]);
printf("size per pro: %dx%d\n", m_per_pro, n_per_pro);
}
int periods[] = {0,0}; // edges are not connected
MPI_Comm cart_comm;
if(MPI_Cart_create(MPI_COMM_WORLD, 2, pro_per_dim, periods, 0, &cart_comm)) {
fprintf(stderr, "Cannot create topology\n");
exit(1);
}
if(cart_comm == MPI_COMM_NULL) {
printf("process %d not in use. exiting...\n", rank);
MPI_Finalize();
exit(0);
}
int coord[2];
if(MPI_Cart_coords(cart_comm, rank, 2, coord)) {
fprintf(stderr, "Cannot get coordinates\n");
exit(1);
}
// calculate own field using coord pi = Calculate_Process_Info(cart_comm, rank, m, n, cell_per_pro);
pi.start_m = coord[0] * m_per_pro;
pi.end_m = (coord[0]+1)*m_per_pro -1;
pi.start_n = coord[1] * n_per_pro;
pi.end_n = (coord[1]+1) * n_per_pro -1;
if(pi.end_m > m - 1) {
pi.end_m = m - 1;
}
if(pi.end_n > n - 1) {
pi.end_n = n - 1;
}
pi.coord0 = coord[0];
pi.coord1 = coord[1];
pi.rank = rank;
int matrix_size[2]; int matrix_size[2];
matrix_size[0] = pi.end_m - pi.start_m + 3; matrix_size[0] = pi.end_m - pi.start_m + 3;
......
#include <mpi.h> #include <mpi.h>
typedef struct {
int rank;
int coord0;
int coord1;
int start_m; // first tile to process in X-axis
int start_n; // first tile to process in Y-axis
int end_m; // last tile to process in X-axis
int end_n; // last tile to process in Y-axis
} t_process_info;
// matrix.c // matrix.c
double ** New_Matrix(int m, int n); double ** New_Matrix(int m, int n);
void Delete_Matrix(double **matrix); void Delete_Matrix(double **matrix);
...@@ -9,19 +19,14 @@ void Insert_Matrix(double **a, int a_dim0, int a_dim1, int pos_dim0, int pos_dim ...@@ -9,19 +19,14 @@ void Insert_Matrix(double **a, int a_dim0, int a_dim1, int pos_dim0, int pos_dim
void Insert_Array_In_Matrix(double **a, int a_dim0, int a_dim1, int pos_dim0, int pos_dim1, double *b, int b_dim0, int b_dim1, int offset_top, int offset_right, int offset_bottom, int offset_left); void Insert_Array_In_Matrix(double **a, int a_dim0, int a_dim1, int pos_dim0, int pos_dim1, double *b, int b_dim0, int b_dim1, int offset_top, int offset_right, int offset_bottom, int offset_left);
// args.c // args.c
void process_args(int argc, char **argv, int *m, int *n, double *eps, double *delta_t); void Process_Args(int argc, char **argv, int *m, int *n, double *eps, double *delta_t);
// mpi_util.c // mpi_util.c
void Create_MPI_Type_t_process_info(MPI_Datatype *datatype); void Create_MPI_Type_t_process_info(MPI_Datatype *datatype);
// // cart.c
void Optimize_Cart_Cluster(int dim0_size, int dim1_size, MPI_Comm comm, int rank, int *pro_per_dim, int *cell_per_pro);
MPI_Comm Create_MPI_Cart_Cluster(MPI_Comm comm, int rank, int *pro_per_dim);
typedef struct { // pi.c
int rank; t_process_info Calculate_Process_Info(MPI_Comm cart_comm, int rank, int dim0_size, int dim1_size, int *cell_per_pro);
int coord0; \ No newline at end of file
int coord1;
int start_m; // first tile to process in X-axis
int start_n; // first tile to process in Y-axis
int end_m; // last tile to process in X-axis
int end_n; // last tile to process in Y-axis
} t_process_info;
\ No newline at end of file
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