From 318a1a40a4ab345f417b8932326d4dd2e68d82bc Mon Sep 17 00:00:00 2001 From: Gilles Gouaillardet Date: Mon, 27 Jul 2015 16:23:08 +0900 Subject: [PATCH] coll/libnbc: ireduce_scatter_block silence malloc(0) warning reported by Lisandro --- .../coll_libnbc_ireduce_scatter_block.c | 129 +++++++++--------- 1 file changed, 65 insertions(+), 64 deletions(-) diff --git a/ompi/mca/coll/libnbc/coll_libnbc_ireduce_scatter_block.c b/ompi/mca/coll/libnbc/coll_libnbc_ireduce_scatter_block.c index 0aca136622..c2546bf747 100644 --- a/ompi/mca/coll/libnbc/coll_libnbc_ireduce_scatter_block.c +++ b/ompi/mca/coll/libnbc/coll_libnbc_ireduce_scatter_block.c @@ -7,7 +7,7 @@ * Copyright (c) 2012 Sandia National Laboratories. All rights reserved. * Copyright (c) 2013 Los Alamos National Security, LLC. All rights * reserved. - * Copyright (c) 2014 Research Organization for Information Science + * Copyright (c) 2014-2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. * * Author(s): Torsten Hoefler @@ -63,80 +63,81 @@ int ompi_coll_libnbc_ireduce_scatter_block(void* sendbuf, void* recvbuf, int rec maxr = (int)ceil((log((double)p)/LOG2)); - count = 0; - for(r=0;rtmpbuf = malloc(ext*count*2); - if(handle->tmpbuf == NULL) { printf("Error in malloc()\n"); return NBC_OOR; } + if (0 < count) { + handle->tmpbuf = malloc(ext*count*2); + if(handle->tmpbuf == NULL) { printf("Error in malloc()\n"); return NBC_OOR; } - redbuf = ((char*)handle->tmpbuf)+(ext*count); + redbuf = ((char*)handle->tmpbuf)+(ext*count); - /* copy data to redbuf if we only have a single node */ - if((p==1) && !inplace) { - res = NBC_Copy(sendbuf, count, datatype, redbuf, count, datatype, comm); - if (NBC_OK != res) { printf("Error in NBC_Copy() (%i)\n", res); return res; } - } + /* copy data to redbuf if we only have a single node */ + if((p==1) && !inplace) { + res = NBC_Copy(sendbuf, count, datatype, redbuf, count, datatype, comm); + if (NBC_OK != res) { printf("Error in NBC_Copy() (%i)\n", res); return res; } + } - firstred = 1; - for(r=1; r<=maxr; r++) { - if((rank % (1<tmpbuf); printf("Error in NBC_Sched_recv() (%i)\n", res); return res; } - /* we have to wait until we have the data */ - res = NBC_Sched_barrier(schedule); - if (NBC_OK != res) { free(handle->tmpbuf); printf("Error in NBC_Sched_barrier() (%i)\n", res); return res; } - if(firstred) { - /* take reduce data from the sendbuf in the first round -> save copy */ - res = NBC_Sched_op(redbuf-(unsigned long)handle->tmpbuf, true, sendbuf, false, 0, true, count, datatype, op, schedule); - firstred = 0; - } else { - /* perform the reduce in my local buffer */ - res = NBC_Sched_op(redbuf-(unsigned long)handle->tmpbuf, true, redbuf-(unsigned long)handle->tmpbuf, true, 0, true, count, datatype, op, schedule); + firstred = 1; + for(r=1; r<=maxr; r++) { + if((rank % (1<tmpbuf); printf("Error in NBC_Sched_recv() (%i)\n", res); return res; } + /* we have to wait until we have the data */ + res = NBC_Sched_barrier(schedule); + if (NBC_OK != res) { free(handle->tmpbuf); printf("Error in NBC_Sched_barrier() (%i)\n", res); return res; } + if(firstred) { + /* take reduce data from the sendbuf in the first round -> save copy */ + res = NBC_Sched_op(redbuf-(unsigned long)handle->tmpbuf, true, sendbuf, false, 0, true, count, datatype, op, schedule); + firstred = 0; + } else { + /* perform the reduce in my local buffer */ + res = NBC_Sched_op(redbuf-(unsigned long)handle->tmpbuf, true, redbuf-(unsigned long)handle->tmpbuf, true, 0, true, count, datatype, op, schedule); + } + if (NBC_OK != res) { free(handle->tmpbuf); printf("Error in NBC_Sched_op() (%i)\n", res); return res; } + /* this cannot be done until handle->tmpbuf is unused :-( */ + res = NBC_Sched_barrier(schedule); + if (NBC_OK != res) { free(handle->tmpbuf); printf("Error in NBC_Sched_barrier() (%i)\n", res); return res; } } - if (NBC_OK != res) { free(handle->tmpbuf); printf("Error in NBC_Sched_op() (%i)\n", res); return res; } - /* this cannot be done until handle->tmpbuf is unused :-( */ - res = NBC_Sched_barrier(schedule); - if (NBC_OK != res) { free(handle->tmpbuf); printf("Error in NBC_Sched_barrier() (%i)\n", res); return res; } - } - } else { - /* we have to send this round */ - peer = rank - (1<<(r-1)); - if(firstred) { - /* we have to send the senbuf */ - res = NBC_Sched_send(sendbuf, false, count, datatype, peer, schedule); } else { - /* we send an already reduced value from redbuf */ - res = NBC_Sched_send(redbuf-(unsigned long)handle->tmpbuf, true, count, datatype, peer, schedule); + /* we have to send this round */ + peer = rank - (1<<(r-1)); + if(firstred) { + /* we have to send the senbuf */ + res = NBC_Sched_send(sendbuf, false, count, datatype, peer, schedule); + } else { + /* we send an already reduced value from redbuf */ + res = NBC_Sched_send(redbuf-(unsigned long)handle->tmpbuf, true, count, datatype, peer, schedule); + } + if (NBC_OK != res) { free(handle->tmpbuf); printf("Error in NBC_Sched_send() (%i)\n", res); return res; } + /* leave the game */ + break; } - if (NBC_OK != res) { free(handle->tmpbuf); printf("Error in NBC_Sched_send() (%i)\n", res); return res; } - /* leave the game */ - break; } - } - res = NBC_Sched_barrier(schedule); - if (NBC_OK != res) { free(handle->tmpbuf); printf("Error in NBC_Sched_barrier() (%i)\n", res); return res; } + res = NBC_Sched_barrier(schedule); + if (NBC_OK != res) { free(handle->tmpbuf); printf("Error in NBC_Sched_barrier() (%i)\n", res); return res; } - /* rank 0 is root and sends - all others receive */ - if(rank != 0) { - res = NBC_Sched_recv(recvbuf, false, recvcount, datatype, 0, schedule); - if (NBC_OK != res) { free(handle->tmpbuf); printf("Error in NBC_Sched_recv() (%i)\n", res); return res; } - } - - if(rank == 0) { - offset = 0; - for(r=1;rtmpbuf, true, recvcount, datatype, r, schedule); - if (NBC_OK != res) { free(handle->tmpbuf); printf("Error in NBC_Sched_send() (%i)\n", res); return res; } + /* rank 0 is root and sends - all others receive */ + if(rank != 0) { + res = NBC_Sched_recv(recvbuf, false, recvcount, datatype, 0, schedule); + if (NBC_OK != res) { free(handle->tmpbuf); printf("Error in NBC_Sched_recv() (%i)\n", res); return res; } + } + + if(rank == 0) { + offset = 0; + for(r=1;rtmpbuf, true, recvcount, datatype, r, schedule); + if (NBC_OK != res) { free(handle->tmpbuf); printf("Error in NBC_Sched_send() (%i)\n", res); return res; } + } + res = NBC_Sched_copy(redbuf-(unsigned long)handle->tmpbuf, true, recvcount, datatype, recvbuf, false, recvcount, datatype, schedule); + if (NBC_OK != res) { free(handle->tmpbuf); printf("Error in NBC_Sched_copy() (%i)\n", res); return res; } } - res = NBC_Sched_copy(redbuf-(unsigned long)handle->tmpbuf, true, recvcount, datatype, recvbuf, false, recvcount, datatype, schedule); - if (NBC_OK != res) { free(handle->tmpbuf); printf("Error in NBC_Sched_copy() (%i)\n", res); return res; } } /*NBC_PRINT_SCHED(*schedule);*/