11#include " flagcx.h"
2- #include " mpi.h"
32#include " tools.h"
43#include < cstring>
54#include < iostream>
@@ -14,27 +13,28 @@ int main(int argc, char *argv[]) {
1413 int num_warmup_iters = args.getWarmupIters ();
1514 int num_iters = args.getTestIters ();
1615 int print_buffer = args.isPrintBuffer ();
17-
18- int totalProcs, proc;
19- MPI_Init (&argc, &argv);
20- MPI_Comm_size (MPI_COMM_WORLD , &totalProcs);
21- MPI_Comm_rank (MPI_COMM_WORLD , &proc);
22- printf (" I am %d of %d\n " , proc, totalProcs);
16+ uint64_t split_mask = args.getSplitMask ();
2317
2418 flagcxHandlerGroup_t handler;
2519 flagcxHandleInit (&handler);
2620 flagcxUniqueId_t &uniqueId = handler->uniqueId ;
2721 flagcxComm_t &comm = handler->comm ;
2822 flagcxDeviceHandle_t &devHandle = handler->devHandle ;
2923
24+ int color = 0 ;
25+ int worldSize = 1 , worldRank = 0 ;
26+ int totalProcs = 1 , proc = 0 ;
27+ MPI_Comm splitComm;
28+ initMpiEnv (argc, argv, worldRank, worldSize, proc, totalProcs, color,
29+ splitComm, split_mask);
30+
3031 int nGpu;
3132 devHandle->getDeviceCount (&nGpu);
32- devHandle->setDevice (proc % nGpu);
33+ devHandle->setDevice (worldRank % nGpu);
3334
3435 if (proc == 0 )
3536 flagcxGetUniqueId (&uniqueId);
36- MPI_Bcast ((void *)uniqueId, sizeof (flagcxUniqueId), MPI_BYTE , 0 ,
37- MPI_COMM_WORLD );
37+ MPI_Bcast ((void *)uniqueId, sizeof (flagcxUniqueId), MPI_BYTE , 0 , splitComm);
3838 MPI_Barrier (MPI_COMM_WORLD );
3939
4040 flagcxCommInitRank (&comm, totalProcs, uniqueId, proc);
@@ -170,7 +170,7 @@ int main(int argc, char *argv[]) {
170170 devHandle->deviceMemcpy (sendbuff, hello, size, flagcxMemcpyHostToDevice,
171171 NULL );
172172
173- if ((proc == 0 || proc == totalProcs - 1 ) && print_buffer) {
173+ if ((proc == 0 || proc == totalProcs - 1 ) && color == 0 && print_buffer) {
174174 printf (" sendbuff = " );
175175 for (int i = 0 ; i < totalProcs; i++) {
176176 printf (" %f " , ((float *)hello)[i * count]);
@@ -218,7 +218,7 @@ int main(int argc, char *argv[]) {
218218 }
219219 }
220220
221- if ((proc == 0 || proc == totalProcs - 1 ) && print_buffer) {
221+ if ((proc == 0 || proc == totalProcs - 1 ) && color == 0 && print_buffer) {
222222 printf (" h_sendcounts = " );
223223 for (int i = 0 ; i < totalProcs; i++) {
224224 printf (" %ld " , h_sendcounts[i]);
@@ -253,13 +253,13 @@ int main(int argc, char *argv[]) {
253253 double elapsed_time = tim.elapsed () / num_iters;
254254 MPI_Allreduce (MPI_IN_PLACE , (void *)&elapsed_time, 1 , MPI_DOUBLE , MPI_SUM ,
255255 MPI_COMM_WORLD );
256- elapsed_time /= totalProcs ;
256+ elapsed_time /= worldSize ;
257257
258258 double base_bw = (double )(size) / 1.0E9 / elapsed_time;
259259 double alg_bw = base_bw;
260260 double factor = ((double )(totalProcs - 1 )) / ((double )(totalProcs));
261261 double bus_bw = base_bw * factor;
262- if (proc == 0 ) {
262+ if (proc == 0 && color == 0 ) {
263263 printf (" Comm size: %zu bytes; Elapsed time: %lf sec; Algo bandwidth: %lf "
264264 " GB/s; Bus bandwidth: %lf GB/s\n " ,
265265 size, elapsed_time, alg_bw, bus_bw);
@@ -270,7 +270,7 @@ int main(int argc, char *argv[]) {
270270 devHandle->deviceMemset (hello, 0 , size, flagcxMemHost, NULL );
271271 devHandle->deviceMemcpy (hello, recvbuff, size, flagcxMemcpyDeviceToHost,
272272 NULL );
273- if ((proc == 0 || proc == totalProcs - 1 ) && print_buffer) {
273+ if ((proc == 0 || proc == totalProcs - 1 ) && color == 0 && print_buffer) {
274274 printf (" recvbuff = " );
275275 for (int i = 0 ; i < totalProcs; i++) {
276276 printf (" %f " , ((float *)hello)[i * count]);
0 commit comments