COMBINATORIAL_BLAS 1.6
 
Loading...
Searching...
No Matches
gathertest.cpp
Go to the documentation of this file.
1#include "CombBLAS/CombBLAS.h"
2#include <mpi.h>
3#include <sys/time.h>
4#include <iostream>
5#include <functional>
6#include <algorithm>
7#include <vector>
8#include <string>
9#include <sstream>
10
11
12
13
14int main(int argc, char* argv[])
15{
16
17 // ------------ initialize MPI ---------------
18 int provided;
19 MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided);
20 if (provided < MPI_THREAD_SERIALIZED)
21 {
22 printf("ERROR: The MPI library does not have MPI_THREAD_SERIALIZED support\n");
23 MPI_Abort(MPI_COMM_WORLD, 1);
24 }
25 int nprocs, myrank;
26 MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
27 MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
28
29
30 {
31 int totalen = (int64_t) atoi(argv[1]);
32 int locallen = totalen/nprocs;
33 totalen = locallen * nprocs;
34
35 vector<int64_t> ind1 (locallen, -1);
36 vector<int64_t> ind2 (locallen, -1);
37 vector<double> val (locallen, 0.0);
38 vector<int> disp(nprocs);
39 vector<int> recvcnt(nprocs);
40 for(int i=0; i<nprocs; i++)
41 {
42 disp[i] = locallen*i;
43 recvcnt[i] = locallen;
44 }
45
46 //double t1 = MPI_Wtime();
47
48 vector<int64_t> recv1 ;
49 vector<int64_t> recv2 ;
50 vector<double> recv3 ;
51
52 if(myrank == 0)
53 {
54 recv1.resize(totalen);
55 recv2.resize(totalen);
56 recv3.resize(totalen);
57 }
58
59 double t1 = MPI_Wtime();
60 MPI_Gatherv(ind1.data(), locallen, MPIType<int64_t>(), recv1.data(), recvcnt.data(), disp.data(), MPIType<int64_t>(), 0, MPI_COMM_WORLD);
61 MPI_Gatherv(ind2.data(), locallen, MPIType<int64_t>(), recv2.data(), recvcnt.data(), disp.data(), MPIType<int64_t>(), 0, MPI_COMM_WORLD);
62 MPI_Gatherv(val.data(), locallen, MPIType<double>(), recv3.data(), recvcnt.data(), disp.data(), MPIType<double>(), 0, MPI_COMM_WORLD);
63
64 double t2 = MPI_Wtime() - t1;
65 if(myrank == 0)
66 {
67 cout << "time : " << t2*2 << endl;
68 }
69 }
70 MPI_Finalize();
71 return 0;
72}
73
74
int main()
Definition Driver.cpp:12
int nprocs
Definition comms.cpp:55
long int64_t
Definition compat.h:21