+/* Copyright (c) 2013-2014. The SimGrid Team.
+ * All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
char *accumbuf = NULL, *accumbuf_free = NULL;
char *local_op_buffer = NULL, *sendtmpbuf = NULL;
ptrdiff_t extent, lower_bound, segment_increment;
char *accumbuf = NULL, *accumbuf_free = NULL;
char *local_op_buffer = NULL, *sendtmpbuf = NULL;
ptrdiff_t extent, lower_bound, segment_increment;
MPI_Request reqs[2] = {MPI_REQUEST_NULL, MPI_REQUEST_NULL};
int num_segments, line, ret, segindex, i, rank;
int recvcount, prevcount, inbi;
MPI_Request reqs[2] = {MPI_REQUEST_NULL, MPI_REQUEST_NULL};
int num_segments, line, ret, segindex, i, rank;
int recvcount, prevcount, inbi;
num_segments = (original_count + count_by_segment - 1) / count_by_segment;
segment_increment = count_by_segment * extent;
num_segments = (original_count + count_by_segment - 1) / count_by_segment;
segment_increment = count_by_segment * extent;
accumbuf = (char*)recvbuf;
if( (NULL == accumbuf) || (root != rank) ) {
/* Allocate temporary accumulator buffer. */
accumbuf = (char*)recvbuf;
if( (NULL == accumbuf) || (root != rank) ) {
/* Allocate temporary accumulator buffer. */
(original_count - 1) * extent);
if (accumbuf_free == NULL) {
line = __LINE__; ret = -1; goto error_hndl;
(original_count - 1) * extent);
if (accumbuf_free == NULL) {
line = __LINE__; ret = -1; goto error_hndl;
sendbuf to the accumbuf, in order to simplfy the loops */
if (!smpi_op_is_commute(op)) {
smpi_datatype_copy(
sendbuf to the accumbuf, in order to simplfy the loops */
if (!smpi_op_is_commute(op)) {
smpi_datatype_copy(
- (char*)accumbuf, original_count, datatype,
- (char*)sendtmpbuf, original_count, datatype);
+ (char*)sendtmpbuf, original_count, datatype,
+ (char*)accumbuf, original_count, datatype);
}
/* Allocate two buffers for incoming segments */
real_segment_size = true_extent + (count_by_segment - 1) * extent;
}
/* Allocate two buffers for incoming segments */
real_segment_size = true_extent + (count_by_segment - 1) * extent;
/* if there is chance to overlap communication -
allocate second buffer */
if( (num_segments > 1) || (tree->tree_nextsize > 1) ) {
/* if there is chance to overlap communication -
allocate second buffer */
if( (num_segments > 1) || (tree->tree_nextsize > 1) ) {
reqs[inbi]=smpi_mpi_irecv(local_recvbuf, recvcount, datatype,
tree->tree_next[i],
reqs[inbi]=smpi_mpi_irecv(local_recvbuf, recvcount, datatype,
tree->tree_next[i],
/* send combined/accumulated data to parent */
smpi_mpi_send( accumulator, prevcount,
datatype, tree->tree_prev,
/* send combined/accumulated data to parent */
smpi_mpi_send( accumulator, prevcount,
datatype, tree->tree_prev,
- if( inbuf_free[0] != NULL) free(inbuf_free[0]);
- if( inbuf_free[1] != NULL) free(inbuf_free[1]);
- if( accumbuf_free != NULL ) free(accumbuf_free);
+ smpi_free_tmp_buffer(inbuf_free[0]);
+ smpi_free_tmp_buffer(inbuf_free[1]);
+ smpi_free_tmp_buffer(accumbuf_free);
segindex * segment_increment,
count_by_segment, datatype,
tree->tree_prev,
segindex * segment_increment,
count_by_segment, datatype,
tree->tree_prev,
segindex * segment_increment,
count_by_segment, datatype,
tree->tree_prev,
segindex * segment_increment,
count_by_segment, datatype,
tree->tree_prev,
segindex * segment_increment,
count_by_segment, datatype,
tree->tree_prev,
segindex * segment_increment,
count_by_segment, datatype,
tree->tree_prev,
- (char*)tmpbuf, count, datatype,
- (char*)recvbuf, count, datatype);
+ (char*)recvbuf, count, datatype,
+ (char*)tmpbuf, count, datatype);
if (root == rank) {
/* Receive result from rank io_root to recvbuf */
smpi_mpi_recv(recvbuf, count, datatype, io_root,
if (root == rank) {
/* Receive result from rank io_root to recvbuf */
smpi_mpi_recv(recvbuf, count, datatype, io_root,
}
} else if (io_root == rank) {
/* Send result from use_this_recvbuf to root */
smpi_mpi_send(use_this_recvbuf, count, datatype, root,
}
} else if (io_root == rank) {
/* Send result from use_this_recvbuf to root */
smpi_mpi_send(use_this_recvbuf, count, datatype, root,
if (rank != root) {
smpi_mpi_send(sbuf, count, dtype, root,
if (rank != root) {
smpi_mpi_send(sbuf, count, dtype, root,
pml_buffer = free_buffer - lb;
}
/* Initialize the receive buffer. */
if (rank == (size - 1)) {
pml_buffer = free_buffer - lb;
}
/* Initialize the receive buffer. */
if (rank == (size - 1)) {
- smpi_datatype_copy((char*)rbuf, count, dtype,
- (char*)sbuf, count, dtype);
+ smpi_datatype_copy((char*)sbuf, count, dtype,(char*)rbuf, count, dtype);
} else {
smpi_mpi_recv(rbuf, count, dtype, size - 1,
} else {
smpi_mpi_recv(rbuf, count, dtype, size - 1,
inbuf = (char*)sbuf;
} else {
smpi_mpi_recv(pml_buffer, count, dtype, i,
inbuf = (char*)sbuf;
} else {
smpi_mpi_recv(pml_buffer, count, dtype, i,
- smpi_datatype_copy((char*)sbuf, count, dtype,
- inplace_temp,count , dtype);
- free(inplace_temp);
+ smpi_datatype_copy(inplace_temp, count, dtype,(char*)sbuf
+ ,count , dtype);
+ smpi_free_tmp_buffer(inplace_temp);