-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
61 lines (51 loc) · 1.48 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <unistd.h>
#include <cstdlib>
#include <mpi.h>
#include "ColumnBlock.h"
#include "InitFunctions.h"
#include "constants.h"
using namespace std;
int main(int argc, char *argv[])
{
///INITIALIZATION PHASE
// Get command line arguments
if ( argc != 3 )
{
printf("Wrong number of arguments.\n");
printf("Usage: %s <array dimention> <grouped columns (0/1)>\n", argv[0]);
return 1;
}
int array_dimention = atoi(argv[1]);
int partition_mode = atoi(argv[2]);
// Initialize the group of columns each process will get
block* proc_block = initialize(array_dimention, partition_mode);
int myrank = MPI::COMM_WORLD.Get_rank();
int proc_num = MPI::COMM_WORLD.Get_size();
//start timer
double start_time = MPI_Wtime();
/// Compute the solution
for ( int k = 0; k < array_dimention; k++ )
{
int max_val_id;
if ( proc_block->local_column(k) )
{
max_val_id = proc_block->find_pivot(k);
}
//send/receive pivoted elem id
//send/receive k column
proc_block->sync(max_val_id, k);
//processing
proc_block->compute_values(k);
}
/// Finalize, print solution
if ( myrank == 0 )
{
cout<<"time: "<<MPI_Wtime() - start_time<<"s"<<endl;
//uncomment next line to print the solution to stdout
//proc_block->print_solution();
}
MPI_Barrier(MPI_COMM_WORLD);
MPI_Finalize();
return 0;
}