int main(int argc, char* argv[]) { int p; int my_rank; GRID_INFO_T grid; LOCAL_MATRIX_T* local_A; LOCAL_MATRIX_T* local_B; LOCAL_MATRIX_T* local_C; int n; int n_bar; double starttime, endtime; srand(time(NULL)); starttime = MPI_Wtime(); void Setup_grid(GRID_INFO_T* grid); void Fox(int n, GRID_INFO_T* grid, LOCAL_MATRIX_T* local_A, LOCAL_MATRIX_T* local_B, LOCAL_MATRIX_T* local_C); MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); /* Need to change the below. Want random matrices.*/ Setup_grid(&grid); if (my_rank == 0) { //printf("What's the order of the matrices?\n"); n = atoi(argv[1]); } MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD); n_bar = n/grid.q; local_A = Local_matrix_allocate(n_bar); Order(local_A) = n_bar; Read_matrix("Generating and distributing A...", local_A, &grid, n); Print_matrix("Matrix A:", local_A, &grid, n); local_B = Local_matrix_allocate(n_bar); Order(local_B) = n_bar; Read_matrix("Generating and distributing B...", local_B, &grid, n); Print_matrix("Matrix B:", local_B, &grid, n); Build_matrix_type(local_A); temp_mat = Local_matrix_allocate(n_bar); local_C = Local_matrix_allocate(n_bar); Order(local_C) = n_bar; Fox(n, &grid, local_A, local_B, local_C); endtime = MPI_Wtime(); Print_matrix("The product is", local_C, &grid, n); if(my_rank == 0) printf("The time it took was %f\n", endtime - starttime); Free_local_matrix(&local_A); Free_local_matrix(&local_B); Free_local_matrix(&local_C); MPI_Type_free(&local_matrix_mpi_t); MPI_Finalize(); return 0; } /* main */
main (int argc, char **argv) { /* Allocate memory for the structure grid */ GRID_INFO_TYPE *grid = (GRID_INFO_TYPE *)malloc(sizeof(GRID_INFO_TYPE)); /* Initialize MPI */ MPI_Init(&argc, &argv); /* Find out this process number */ MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* Find out the number of processes */ MPI_Comm_size(MPI_COMM_WORLD, &nworkers); Setup_grid(grid); int itime; int i; int big_energy,E; int big_mag,M; double E_per_spin; double M_per_spin; NP=sqrt(nworkers); iseed=iseed*(rank+1); itime = 0; big_energy = 0; big_mag = 0; /* get started */ initialize(grid,spin, nbr1, nbr2); boundary(grid,spin, nbr1, nbr2); /* warm up system */ for (i = 1 ; i <= WARM; i++) { itime = i; mcmove(grid,spin, nbr1, nbr2); boundary(grid,spin, nbr1, nbr2); } /* do Monte Carlo steps and collect stuff for averaging */ for (i = (WARM + 1) ; i <= MCS; i++) { itime = i; mcmove(grid,spin, nbr1, nbr2); if(i!=MCS)boundary(grid,spin, nbr1, nbr2); big_mag = big_mag + total_mag(spin); big_energy = big_energy + total_energy(spin,nbr1,nbr2); } printf("Mag %f rank %d time %d\n", 1.0*big_mag/(MCS-WARM), rank, MCS-WARM); MPI_Reduce (&big_mag, &M,1,MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); /* process 0 adds total magentization from each process to find the net magnetization. */ MPI_Reduce (&big_energy, &E,1,MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); if(rank==0) { M_per_spin = (float)M/((MCS - WARM)*(nworkers*(LENGTH-2)*(LENGTH-2))); E_per_spin = (float)E/((MCS - WARM)*nworkers*((LENGTH-2)*(LENGTH-2))); // finish off printf("Mag %d Mag/spin %lf rank %d\n",M, M_per_spin, rank); printf("Energy %d Energy/spin %lf rank %d\n",E, E_per_spin, rank); printf("Analytic: Mag/spin %f, Energy/spin -2 to 0\n", mag_analytic(TEMP)); printf("Temperature %lf, Edge length of system %d \n", TEMP , LENGTH); printf("No. of warm-up steps %d, No. of MCS %d \n", WARM , MCS); } print_config(grid, spin, itime ); MPI_Finalize(); /* exit all MPI functions */ }