2004-01-12 00:26:55 +03:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
2006-08-24 20:38:08 +04:00
|
|
|
* Copyright (c) 2004-2006 The University of Tennessee and The University
|
2005-11-05 22:57:48 +03:00
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-01-12 00:26:55 +03:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#include "ompi_config.h"
|
2004-02-15 00:26:30 +03:00
|
|
|
#include "coll_basic.h"
|
2004-01-12 00:26:55 +03:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "mpi.h"
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "ompi/constants.h"
|
2005-09-13 00:21:53 +04:00
|
|
|
#include "ompi/op/op.h"
|
|
|
|
#include "ompi/mca/coll/coll.h"
|
|
|
|
#include "ompi/mca/coll/base/coll_tags.h"
|
2004-01-12 00:26:55 +03:00
|
|
|
#include "coll_basic.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* scan
|
|
|
|
*
|
|
|
|
* Function: - basic scan operation
|
|
|
|
* Accepts: - same arguments as MPI_Scan()
|
|
|
|
* Returns: - MPI_SUCCESS or error code
|
|
|
|
*/
|
2005-08-10 14:51:42 +04:00
|
|
|
int
|
|
|
|
mca_coll_basic_scan_intra(void *sbuf, void *rbuf, int count,
|
2005-08-10 21:53:43 +04:00
|
|
|
struct ompi_datatype_t *dtype,
|
|
|
|
struct ompi_op_t *op,
|
2007-08-19 07:37:49 +04:00
|
|
|
struct ompi_communicator_t *comm,
|
2008-07-29 02:40:57 +04:00
|
|
|
mca_coll_base_module_t *module)
|
2004-01-12 00:26:55 +03:00
|
|
|
{
|
2006-10-18 00:20:58 +04:00
|
|
|
int size, rank, err;
|
|
|
|
ptrdiff_t true_lb, true_extent, lb, extent;
|
2005-08-10 14:51:42 +04:00
|
|
|
char *free_buffer = NULL;
|
|
|
|
char *pml_buffer = NULL;
|
2004-01-12 00:26:55 +03:00
|
|
|
|
2005-08-10 14:51:42 +04:00
|
|
|
/* Initialize */
|
2004-01-12 00:26:55 +03:00
|
|
|
|
2005-08-10 14:51:42 +04:00
|
|
|
rank = ompi_comm_rank(comm);
|
|
|
|
size = ompi_comm_size(comm);
|
2004-01-12 00:26:55 +03:00
|
|
|
|
2005-08-10 14:51:42 +04:00
|
|
|
/* If I'm rank 0, just copy into the receive buffer */
|
2004-01-12 00:26:55 +03:00
|
|
|
|
2005-08-10 14:51:42 +04:00
|
|
|
if (0 == rank) {
|
2005-09-14 00:06:54 +04:00
|
|
|
if (MPI_IN_PLACE != sbuf) {
|
2006-08-24 20:38:08 +04:00
|
|
|
err = ompi_ddt_copy_content_same_ddt(dtype, count, (char*)rbuf, (char*)sbuf);
|
2005-09-14 00:06:54 +04:00
|
|
|
if (MPI_SUCCESS != err) {
|
|
|
|
return err;
|
|
|
|
}
|
2005-08-10 21:53:43 +04:00
|
|
|
}
|
2004-01-12 00:26:55 +03:00
|
|
|
}
|
|
|
|
|
2005-08-10 14:51:42 +04:00
|
|
|
/* Otherwise receive previous buffer and reduce. */
|
2004-06-29 07:23:01 +04:00
|
|
|
|
2005-08-10 14:51:42 +04:00
|
|
|
else {
|
2005-08-10 21:53:43 +04:00
|
|
|
/* Allocate a temporary buffer. Rationale for this size is
|
|
|
|
* listed in coll_basic_reduce.c. Use this temporary buffer to
|
|
|
|
* receive into, later. */
|
|
|
|
|
2005-09-14 00:06:54 +04:00
|
|
|
ompi_ddt_get_extent(dtype, &lb, &extent);
|
|
|
|
ompi_ddt_get_true_extent(dtype, &true_lb, &true_extent);
|
2005-08-10 21:53:43 +04:00
|
|
|
|
2006-08-24 20:38:08 +04:00
|
|
|
free_buffer = (char*)malloc(true_extent + (count - 1) * extent);
|
2005-09-14 00:06:54 +04:00
|
|
|
if (NULL == free_buffer) {
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
2005-08-10 21:53:43 +04:00
|
|
|
}
|
2005-09-14 00:06:54 +04:00
|
|
|
pml_buffer = free_buffer - lb;
|
2005-08-10 21:53:43 +04:00
|
|
|
|
|
|
|
/* Copy the send buffer into the receive buffer. */
|
|
|
|
|
2005-09-14 00:06:54 +04:00
|
|
|
if (MPI_IN_PLACE != sbuf) {
|
2006-08-24 20:38:08 +04:00
|
|
|
err = ompi_ddt_copy_content_same_ddt(dtype, count, (char*)rbuf, (char*)sbuf);
|
2005-09-14 00:06:54 +04:00
|
|
|
if (MPI_SUCCESS != err) {
|
|
|
|
if (NULL != free_buffer) {
|
|
|
|
free(free_buffer);
|
|
|
|
}
|
|
|
|
return err;
|
2005-08-10 21:53:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Receive the prior answer */
|
|
|
|
|
|
|
|
err = MCA_PML_CALL(recv(pml_buffer, count, dtype,
|
|
|
|
rank - 1, MCA_COLL_BASE_TAG_SCAN, comm,
|
|
|
|
MPI_STATUS_IGNORE));
|
|
|
|
if (MPI_SUCCESS != err) {
|
|
|
|
if (NULL != free_buffer) {
|
|
|
|
free(free_buffer);
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform the operation */
|
|
|
|
|
|
|
|
ompi_op_reduce(op, pml_buffer, rbuf, count, dtype);
|
|
|
|
|
|
|
|
/* All done */
|
|
|
|
|
|
|
|
if (NULL != free_buffer) {
|
|
|
|
free(free_buffer);
|
|
|
|
}
|
2004-06-29 07:23:01 +04:00
|
|
|
}
|
2004-01-12 00:26:55 +03:00
|
|
|
|
2005-08-10 14:51:42 +04:00
|
|
|
/* Send result to next process. */
|
2004-01-12 00:26:55 +03:00
|
|
|
|
2005-08-10 14:51:42 +04:00
|
|
|
if (rank < (size - 1)) {
|
2005-08-10 21:53:43 +04:00
|
|
|
return MCA_PML_CALL(send(rbuf, count, dtype, rank + 1,
|
|
|
|
MCA_COLL_BASE_TAG_SCAN,
|
|
|
|
MCA_PML_BASE_SEND_STANDARD, comm));
|
2005-08-10 14:51:42 +04:00
|
|
|
}
|
2004-01-12 00:26:55 +03:00
|
|
|
|
2005-08-10 14:51:42 +04:00
|
|
|
/* All done */
|
2004-01-12 00:26:55 +03:00
|
|
|
|
2005-08-10 14:51:42 +04:00
|
|
|
return MPI_SUCCESS;
|
2004-01-12 00:26:55 +03:00
|
|
|
}
|