-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfast_allreduce.cpp
More file actions
85 lines (66 loc) · 2.29 KB
/
Copy pathfast_allreduce.cpp
File metadata and controls
85 lines (66 loc) · 2.29 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "mpi.h"
#include <vector>
#include <cmath>
#include <cstdio>
#include <stdlib.h>
#include <time.h>
#include <hip/hip_runtime.h>
#include "profs_allreduce.hpp"
#include "class_allreduce.hpp"
int main(int argc, char* argv[])
{
MPI_Init(&argc, &argv);
int rank, num_procs;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
int size = 1 << 28;
std::vector<float> sendbuf(size);
std::vector<float> recvbuf_class(size);
std::vector<float> recvbuf_prof(size);
// Initialize sendbuf to random values
srand(rank*time(NULL));
for (int i = 0; i < size; i++)
sendbuf[i] = rand() / RAND_MAX;
// Initialize sendbuf to random values
srand(rank*time(NULL));
for (int i = 0; i < size; i++)
sendbuf[i] = rand() / RAND_MAX;
double time;
/************************************
* Class GPT's Allreduce
* **********************************/
// Initialize Persistent Allreduce
ClassAllreduce* class_allreduce = new ClassAllreduce(sendbuf.data(), recvbuf_class.data(), size,
MPI_FLOAT, MPI_SUM, MPI_COMM_WORLD);
// Time Persistent Allreduce
std::fill(recvbuf_class.begin(), recvbuf_class.end(), 0);
time = class_allreduce->time_it();
delete class_allreduce;
// Print Timing
if (rank == 0) printf("Class + GPT's Allreduce: %e\n", time);
/************************************
* Professor Bienz's Allreduce
* **********************************/
// Initialize Persistent Allreduce
ProfsAllreduce* prof_allreduce = new ProfsAllreduce(sendbuf.data(), recvbuf_prof.data(), size,
MPI_FLOAT, MPI_SUM, MPI_COMM_WORLD);
// Time Persistent Allreduce
std::fill(recvbuf_prof.begin(), recvbuf_prof.end(), 0);
time = prof_allreduce->time_it();
delete prof_allreduce;
// Print Timing
if (rank == 0) printf("Professor Bienz's Allreduce: %e\n", time);
/************************************
* Check for Correctness
* **********************************/
for (int i = 0; i < size; i++)
{
if (fabs((recvbuf_prof[i] - recvbuf_class[i])/recvbuf_prof[i]) > 1e-04)
{
printf("DIFFERENCE IN SOLUTIONS!\n");
MPI_Abort(MPI_COMM_WORLD, -1);
}
}
MPI_Finalize();
return 0;
}