本文整理汇总了C++中smpi_comm_size函数的典型用法代码示例。如果您正苦于以下问题:C++ smpi_comm_size函数的具体用法?C++ smpi_comm_size怎么用?C++ smpi_comm_size使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了smpi_comm_size函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: smpi_coll_tuned_alltoall_ompi2
int smpi_coll_tuned_alltoall_ompi2(void *sendbuf, int sendcount,
MPI_Datatype sendtype, void *recvbuf,
int recvcount, MPI_Datatype recvtype,
MPI_Comm comm)
{
int size, sendsize;
size = smpi_comm_size(comm);
sendsize = smpi_datatype_size(sendtype) * sendcount;
if (sendsize < 200 && size > 12) {
return
smpi_coll_tuned_alltoall_bruck(sendbuf, sendcount, sendtype,
recvbuf, recvcount, recvtype,
comm);
} else if (sendsize < 3000) {
return
smpi_coll_tuned_alltoall_basic_linear(sendbuf, sendcount,
sendtype, recvbuf,
recvcount, recvtype, comm);
} else {
return
smpi_coll_tuned_alltoall_ring(sendbuf, sendcount, sendtype,
recvbuf, recvcount, recvtype,
comm);
}
}
示例2: smpi_coll_tuned_allgather_NTSLR_NB
// Allgather-Non-Topoloty-Scecific-Logical-Ring algorithm
int
smpi_coll_tuned_allgather_NTSLR_NB(void *sbuf, int scount, MPI_Datatype stype,
void *rbuf, int rcount, MPI_Datatype rtype,
MPI_Comm comm)
{
MPI_Aint rextent, sextent;
MPI_Status status, status2;
int i, to, from, rank, size;
int send_offset, recv_offset;
int tag = COLL_TAG_ALLGATHER;
rank = smpi_comm_rank(comm);
size = smpi_comm_size(comm);
rextent = smpi_datatype_get_extent(rtype);
sextent = smpi_datatype_get_extent(stype);
MPI_Request *rrequest_array;
MPI_Request *srequest_array;
rrequest_array = (MPI_Request *) xbt_malloc(size * sizeof(MPI_Request));
srequest_array = (MPI_Request *) xbt_malloc(size * sizeof(MPI_Request));
// irregular case use default MPI fucntions
if (scount * sextent != rcount * rextent) {
XBT_WARN("MPI_allgather_NTSLR_NB use default MPI_allgather.");
smpi_mpi_allgather(sbuf, scount, stype, rbuf, rcount, rtype, comm);
return MPI_SUCCESS;
}
// topo non-specific
to = (rank + 1) % size;
from = (rank + size - 1) % size;
//copy a single segment from sbuf to rbuf
send_offset = rank * scount * sextent;
smpi_mpi_sendrecv(sbuf, scount, stype, rank, tag,
(char *)rbuf + send_offset, rcount, rtype, rank, tag, comm, &status);
//start sending logical ring message
int increment = scount * sextent;
//post all irecv first
for (i = 0; i < size - 1; i++) {
recv_offset = ((rank - i - 1 + size) % size) * increment;
rrequest_array[i] = smpi_mpi_irecv((char *)rbuf + recv_offset, rcount, rtype, from, tag + i, comm);
}
for (i = 0; i < size - 1; i++) {
send_offset = ((rank - i + size) % size) * increment;
srequest_array[i] = smpi_mpi_isend((char *)rbuf + send_offset, scount, stype, to, tag + i, comm);
smpi_mpi_wait(&rrequest_array[i], &status);
smpi_mpi_wait(&srequest_array[i], &status2);
}
free(rrequest_array);
free(srequest_array);
return MPI_SUCCESS;
}
示例3: smpi_coll_tuned_alltoall_ompi
int smpi_coll_tuned_alltoall_ompi( void *sbuf, int scount,
MPI_Datatype sdtype,
void* rbuf, int rcount,
MPI_Datatype rdtype,
MPI_Comm comm)
{
int communicator_size;
size_t dsize, block_dsize;
communicator_size = smpi_comm_size(comm);
/* Decision function based on measurement on Grig cluster at
the University of Tennessee (2GB MX) up to 64 nodes.
Has better performance for messages of intermediate sizes than the old one */
/* determine block size */
dsize = smpi_datatype_size(sdtype);
block_dsize = dsize * scount;
if ((block_dsize < 200) && (communicator_size > 12)) {
return smpi_coll_tuned_alltoall_bruck(sbuf, scount, sdtype,
rbuf, rcount, rdtype,
comm);
} else if (block_dsize < 3000) {
return smpi_coll_tuned_alltoall_basic_linear(sbuf, scount, sdtype,
rbuf, rcount, rdtype,
comm);
}
return smpi_coll_tuned_alltoall_ring (sbuf, scount, sdtype,
rbuf, rcount, rdtype,
comm);
}
示例4: smpi_coll_tuned_alltoallv_pair_mpi_barrier
/*****************************************************************************
* Function: alltoall_pair_mpi_barrier
* Return: int
* Inputs:
send_buff: send input buffer
send_count: number of elements to send
send_type: data type of elements being sent
recv_buff: receive output buffer
recv_count: number of elements to received
recv_type: data type of elements being received
comm: communicator
* Descrp: Function works when P is power of two. In each phase of P - 1
phases, nodes in pair communicate their data. MPI barriers are
inserted between each two phases.
* Auther: Ahmad Faraj
****************************************************************************/
int
smpi_coll_tuned_alltoallv_pair_mpi_barrier(void *send_buff, int *send_counts, int *send_disps,
MPI_Datatype send_type,
void *recv_buff, int *recv_counts, int *recv_disps,
MPI_Datatype recv_type, MPI_Comm comm)
{
MPI_Status s;
MPI_Aint send_chunk, recv_chunk;
int i, src, dst, rank, num_procs;
int tag = 101;
char *send_ptr = (char *) send_buff;
char *recv_ptr = (char *) recv_buff;
rank = smpi_comm_rank(comm);
num_procs = smpi_comm_size(comm);
send_chunk = smpi_datatype_get_extent(send_type);
recv_chunk = smpi_datatype_get_extent(recv_type);
for (i = 0; i < num_procs; i++) {
src = dst = rank ^ i;
smpi_mpi_barrier(comm);
smpi_mpi_sendrecv(send_ptr + send_disps[dst] * send_chunk, send_counts[dst], send_type, dst,
tag, recv_ptr + recv_disps[src] * recv_chunk, recv_counts[src], recv_type,
src, tag, comm, &s);
}
return MPI_SUCCESS;
}
示例5: smpi_coll_tuned_alltoall_ring
/*****************************************************************************
* Function: alltoall_ring
* Return: int
* Inputs:
send_buff: send input buffer
send_count: number of elements to send
send_type: data type of elements being sent
recv_buff: receive output buffer
recv_count: number of elements to received
recv_type: data type of elements being received
comm: communicator
* Descrp: Function works in P - 1 steps. In step i, node j - i -> j -> j + i.
* Auther: Ahmad Faraj
****************************************************************************/
int
smpi_coll_tuned_alltoall_ring(void *send_buff, int send_count,
MPI_Datatype send_type, void *recv_buff,
int recv_count, MPI_Datatype recv_type,
MPI_Comm comm)
{
MPI_Status s;
MPI_Aint send_chunk, recv_chunk;
int i, src, dst, rank, num_procs;
int tag = COLL_TAG_ALLTOALL;
char *send_ptr = (char *) send_buff;
char *recv_ptr = (char *) recv_buff;
rank = smpi_comm_rank(comm);
num_procs = smpi_comm_size(comm);
send_chunk = smpi_datatype_get_extent(send_type);
recv_chunk = smpi_datatype_get_extent(recv_type);
send_chunk *= send_count;
recv_chunk *= recv_count;
for (i = 0; i < num_procs; i++) {
src = (rank - i + num_procs) % num_procs;
dst = (rank + i) % num_procs;
smpi_mpi_sendrecv(send_ptr + dst * send_chunk, send_count, send_type, dst,
tag, recv_ptr + src * recv_chunk, recv_count, recv_type,
src, tag, comm, &s);
}
return MPI_SUCCESS;
}
示例6: smpi_coll_tuned_bcast_flattree
int
smpi_coll_tuned_bcast_flattree(void *buff, int count, MPI_Datatype data_type,
int root, MPI_Comm comm)
{
MPI_Request *req_ptr;
MPI_Request *reqs;
int i, rank, num_procs;
int tag = 1;
rank = smpi_comm_rank(comm);
num_procs = smpi_comm_size(comm);
if (rank != root) {
smpi_mpi_recv(buff, count, data_type, root, tag, comm, MPI_STATUS_IGNORE);
}
else {
reqs = (MPI_Request *) xbt_malloc((num_procs - 1) * sizeof(MPI_Request));
req_ptr = reqs;
// Root sends data to all others
for (i = 0; i < num_procs; i++) {
if (i == rank)
continue;
*(req_ptr++) = smpi_mpi_isend(buff, count, data_type, i, tag, comm);
}
// wait on all requests
smpi_mpi_waitall(num_procs - 1, reqs, MPI_STATUSES_IGNORE);
free(reqs);
}
return MPI_SUCCESS;
}
示例7: smpi_coll_tuned_reduce_ompi_chain
int smpi_coll_tuned_reduce_ompi_chain( void *sendbuf, void *recvbuf, int count,
MPI_Datatype datatype,
MPI_Op op, int root,
MPI_Comm comm
)
{
uint32_t segsize=64*1024;
int segcount = count;
size_t typelng;
int fanout = smpi_comm_size(comm)/2;
XBT_DEBUG("coll:tuned:reduce_intra_chain rank %d fo %d ss %5d", smpi_comm_rank(comm), fanout, segsize);
/**
* Determine number of segments and number of elements
* sent per operation
*/
typelng = smpi_datatype_size( datatype);
COLL_TUNED_COMPUTED_SEGCOUNT( segsize, typelng, segcount );
return smpi_coll_tuned_ompi_reduce_generic( sendbuf, recvbuf, count, datatype,
op, root, comm,
ompi_coll_tuned_topo_build_chain(fanout, comm, root),
segcount, 0 );
}
示例8: smpi_coll_tuned_allgather_ring
/*****************************************************************************
* Function: allgather_ring
* return: int
* inputs:
* send_buff: send input buffer
* send_count: number of elements to send
* send_type: data type of elements being sent
* recv_buff: receive output buffer
* recv_count: number of elements to received
* recv_type: data type of elements being received
* comm: communication
* Descrp: Function works in P - 1 steps. In step i, node j - i -> j -> j+ i.
* Auther: Ahmad Faraj
****************************************************************************/
int
smpi_coll_tuned_allgather_ring(void *send_buff, int send_count,
MPI_Datatype send_type, void *recv_buff,
int recv_count, MPI_Datatype recv_type,
MPI_Comm comm)
{
MPI_Aint extent;
int i, src, dst, rank, num_procs;
int tag = 1;
MPI_Status status;
char *sendptr = (char *) send_buff;
char *recvptr = (char *) recv_buff;
rank = smpi_comm_rank(comm);
num_procs = smpi_comm_size(comm);
extent = smpi_datatype_get_extent(send_type);
// local send/recv
smpi_mpi_sendrecv(sendptr, send_count, send_type, rank, tag,
recvptr + rank * recv_count * extent,
recv_count, recv_type, rank, tag, comm, &status);
for (i = 1; i < num_procs; i++) {
src = (rank - i + num_procs) % num_procs;
dst = (rank + i) % num_procs;
smpi_mpi_sendrecv(sendptr, send_count, send_type, dst, tag,
recvptr + src * recv_count * extent, recv_count, recv_type,
src, tag, comm, &status);
}
return MPI_SUCCESS;
}
示例9: smpi_coll_tuned_barrier_ompi_bruck
int smpi_coll_tuned_barrier_ompi_bruck(MPI_Comm comm
)
{
int rank, size;
int distance, to, from;
rank = smpi_comm_rank(comm);
size = smpi_comm_size(comm);
XBT_DEBUG(
"ompi_coll_tuned_barrier_ompi_bruck rank %d", rank);
/* exchange data with rank-2^k and rank+2^k */
for (distance = 1; distance < size; distance <<= 1) {
from = (rank + size - distance) % size;
to = (rank + distance) % size;
/* send message to lower ranked node */
smpi_mpi_sendrecv(NULL, 0, MPI_BYTE, to,
COLL_TAG_BARRIER,
NULL, 0, MPI_BYTE, from,
COLL_TAG_BARRIER,
comm, MPI_STATUS_IGNORE);
}
return MPI_SUCCESS;
}
示例10: smpi_coll_tuned_reduce_flat_tree
int
smpi_coll_tuned_reduce_flat_tree(void *sbuf, void *rbuf, int count,
MPI_Datatype dtype, MPI_Op op,
int root, MPI_Comm comm)
{
int i, tag = 4321;
int size;
int rank;
MPI_Aint extent;
char *origin = 0;
char *inbuf;
MPI_Status status;
rank = smpi_comm_rank(comm);
size = smpi_comm_size(comm);
/* If not root, send data to the root. */
extent = smpi_datatype_get_extent(dtype);
if (rank != root) {
smpi_mpi_send(sbuf, count, dtype, root, tag, comm);
return 0;
}
/* Root receives and reduces messages. Allocate buffer to receive
messages. */
if (size > 1)
origin = (char *) xbt_malloc(count * extent);
/* Initialize the receive buffer. */
if (rank == (size - 1))
smpi_mpi_sendrecv(sbuf, count, dtype, rank, tag,
rbuf, count, dtype, rank, tag, comm, &status);
else
smpi_mpi_recv(rbuf, count, dtype, size - 1, tag, comm, &status);
/* Loop receiving and calling reduction function (C or Fortran). */
for (i = size - 2; i >= 0; --i) {
if (rank == i)
inbuf = sbuf;
else {
smpi_mpi_recv(origin, count, dtype, i, tag, comm, &status);
inbuf = origin;
}
/* Call reduction function. */
smpi_op_apply(op, inbuf, rbuf, &count, &dtype);
}
if (origin)
free(origin);
/* All done */
return 0;
}
示例11: smpi_coll_tuned_scatter_ompi_basic_linear
/*
* scatter_intra
*
* Function: - basic scatter operation
* Accepts: - same arguments as MPI_Scatter()
* Returns: - MPI_SUCCESS or error code
*/
int
smpi_coll_tuned_scatter_ompi_basic_linear(void *sbuf, int scount,
MPI_Datatype sdtype,
void *rbuf, int rcount,
MPI_Datatype rdtype,
int root,
MPI_Comm comm
)
{
int i, rank, size, err;
char *ptmp;
ptrdiff_t lb, incr;
/* Initialize */
rank = smpi_comm_rank(comm);
size = smpi_comm_size(comm);
/* If not root, receive data. */
if (rank != root) {
smpi_mpi_recv(rbuf, rcount, rdtype, root,
COLL_TAG_SCATTER,
comm, MPI_STATUS_IGNORE);
return MPI_SUCCESS;
}
/* I am the root, loop sending data. */
err = smpi_datatype_extent(sdtype, &lb, &incr);
if (MPI_SUCCESS != err) {
return MPI_ERR_OTHER;
}
incr *= scount;
for (i = 0, ptmp = (char *) sbuf; i < size; ++i, ptmp += incr) {
/* simple optimization */
if (i == rank) {
if (MPI_IN_PLACE != rbuf) {
err =
smpi_datatype_copy(ptmp, scount, sdtype, rbuf, rcount,
rdtype);
}
} else {
smpi_mpi_send(ptmp, scount, sdtype, i,
COLL_TAG_SCATTER,
comm);
}
if (MPI_SUCCESS != err) {
return err;
}
}
/* All done */
return MPI_SUCCESS;
}
示例12: smpi_coll_tuned_gather_ompi
int smpi_coll_tuned_gather_ompi(void *sbuf, int scount,
MPI_Datatype sdtype,
void* rbuf, int rcount,
MPI_Datatype rdtype,
int root,
MPI_Comm comm
)
{
//const int large_segment_size = 32768;
//const int small_segment_size = 1024;
//const size_t large_block_size = 92160;
const size_t intermediate_block_size = 6000;
const size_t small_block_size = 1024;
const int large_communicator_size = 60;
const int small_communicator_size = 10;
int communicator_size, rank;
size_t dsize, block_size;
XBT_DEBUG("smpi_coll_tuned_gather_ompi");
communicator_size = smpi_comm_size(comm);
rank = smpi_comm_rank(comm);
// Determine block size
if (rank == root) {
dsize = smpi_datatype_size(rdtype);
block_size = dsize * rcount;
} else {
dsize = smpi_datatype_size(sdtype);
block_size = dsize * scount;
}
/* if (block_size > large_block_size) {*/
/* return smpi_coll_tuned_gather_ompi_linear_sync (sbuf, scount, sdtype, */
/* rbuf, rcount, rdtype, */
/* root, comm);*/
/* } else*/ if (block_size > intermediate_block_size) {
return smpi_coll_tuned_gather_ompi_linear_sync (sbuf, scount, sdtype,
rbuf, rcount, rdtype,
root, comm);
} else if ((communicator_size > large_communicator_size) ||
((communicator_size > small_communicator_size) &&
(block_size < small_block_size))) {
return smpi_coll_tuned_gather_ompi_binomial (sbuf, scount, sdtype,
rbuf, rcount, rdtype,
root, comm);
}
// Otherwise, use basic linear
return smpi_coll_tuned_gather_ompi_basic_linear (sbuf, scount, sdtype,
rbuf, rcount, rdtype,
root, comm);
}
示例13: smpi_coll_tuned_reduce_scatter_ompi
int smpi_coll_tuned_reduce_scatter_ompi( void *sbuf, void *rbuf,
int *rcounts,
MPI_Datatype dtype,
MPI_Op op,
MPI_Comm comm
)
{
int comm_size, i, pow2;
size_t total_message_size, dsize;
const double a = 0.0012;
const double b = 8.0;
const size_t small_message_size = 12 * 1024;
const size_t large_message_size = 256 * 1024;
int zerocounts = 0;
XBT_DEBUG("smpi_coll_tuned_reduce_scatter_ompi");
comm_size = smpi_comm_size(comm);
// We need data size for decision function
dsize=smpi_datatype_size(dtype);
total_message_size = 0;
for (i = 0; i < comm_size; i++) {
total_message_size += rcounts[i];
if (0 == rcounts[i]) {
zerocounts = 1;
}
}
if( !smpi_op_is_commute(op) || (zerocounts)) {
smpi_mpi_reduce_scatter (sbuf, rbuf, rcounts,
dtype, op,
comm);
return MPI_SUCCESS;
}
total_message_size *= dsize;
// compute the nearest power of 2
for (pow2 = 1; pow2 < comm_size; pow2 <<= 1);
if ((total_message_size <= small_message_size) ||
((total_message_size <= large_message_size) && (pow2 == comm_size)) ||
(comm_size >= a * total_message_size + b)) {
return
smpi_coll_tuned_reduce_scatter_ompi_basic_recursivehalving(sbuf, rbuf, rcounts,
dtype, op,
comm);
}
return smpi_coll_tuned_reduce_scatter_ompi_ring(sbuf, rbuf, rcounts,
dtype, op,
comm);
}
示例14: smpi_coll_tuned_barrier_ompi_doublering
/*
* Simple double ring version of barrier
*
* synchronous gurantee made by last ring of sends are synchronous
*
*/
int smpi_coll_tuned_barrier_ompi_doublering(MPI_Comm comm
)
{
int rank, size;
int left, right;
rank = smpi_comm_rank(comm);
size = smpi_comm_size(comm);
XBT_DEBUG("ompi_coll_tuned_barrier_ompi_doublering rank %d", rank);
left = ((rank-1+size)%size);
right = ((rank+1)%size);
if (rank > 0) { /* receive message from the left */
smpi_mpi_recv((void*)NULL, 0, MPI_BYTE, left,
COLL_TAG_BARRIER, comm,
MPI_STATUS_IGNORE);
}
/* Send message to the right */
smpi_mpi_send((void*)NULL, 0, MPI_BYTE, right,
COLL_TAG_BARRIER,
comm);
/* root needs to receive from the last node */
if (rank == 0) {
smpi_mpi_recv((void*)NULL, 0, MPI_BYTE, left,
COLL_TAG_BARRIER, comm,
MPI_STATUS_IGNORE);
}
/* Allow nodes to exit */
if (rank > 0) { /* post Receive from left */
smpi_mpi_recv((void*)NULL, 0, MPI_BYTE, left,
COLL_TAG_BARRIER, comm,
MPI_STATUS_IGNORE);
}
/* send message to the right one */
smpi_mpi_send((void*)NULL, 0, MPI_BYTE, right,
COLL_TAG_BARRIER,
comm);
/* rank 0 post receive from the last node */
if (rank == 0) {
smpi_mpi_recv((void*)NULL, 0, MPI_BYTE, left,
COLL_TAG_BARRIER, comm,
MPI_STATUS_IGNORE);
}
return MPI_SUCCESS;
}
示例15: smpi_coll_tuned_alltoall_basic_linear
/**
* Alltoall basic_linear (STARMPI:alltoall-simple)
**/
int smpi_coll_tuned_alltoall_basic_linear(void *sendbuf, int sendcount,
MPI_Datatype sendtype,
void *recvbuf, int recvcount,
MPI_Datatype recvtype,
MPI_Comm comm)
{
int system_tag = 888;
int i, rank, size, err, count;
MPI_Aint lb = 0, sendext = 0, recvext = 0;
MPI_Request *requests;
/* Initialize. */
rank = smpi_comm_rank(comm);
size = smpi_comm_size(comm);
XBT_DEBUG("<%d> algorithm alltoall_basic_linear() called.", rank);
smpi_datatype_extent(sendtype, &lb, &sendext);
smpi_datatype_extent(recvtype, &lb, &recvext);
/* simple optimization */
err = smpi_datatype_copy((char *)sendbuf + rank * sendcount * sendext,
sendcount, sendtype,
(char *)recvbuf + rank * recvcount * recvext,
recvcount, recvtype);
if (err == MPI_SUCCESS && size > 1) {
/* Initiate all send/recv to/from others. */
requests = xbt_new(MPI_Request, 2 * (size - 1));
/* Post all receives first -- a simple optimization */
count = 0;
for (i = (rank + 1) % size; i != rank; i = (i + 1) % size) {
requests[count] =
smpi_irecv_init((char *)recvbuf + i * recvcount * recvext, recvcount,
recvtype, i, system_tag, comm);
count++;
}
/* Now post all sends in reverse order
* - We would like to minimize the search time through message queue
* when messages actually arrive in the order in which they were posted.
* TODO: check the previous assertion
*/
for (i = (rank + size - 1) % size; i != rank; i = (i + size - 1) % size) {
requests[count] =
smpi_isend_init((char *)sendbuf + i * sendcount * sendext, sendcount,
sendtype, i, system_tag, comm);
count++;
}
/* Wait for them all. */
smpi_mpi_startall(count, requests);
XBT_DEBUG("<%d> wait for %d requests", rank, count);
smpi_mpi_waitall(count, requests, MPI_STATUS_IGNORE);
for(i = 0; i < count; i++) {
if(requests[i]!=MPI_REQUEST_NULL) smpi_mpi_request_free(&requests[i]);
}
xbt_free(requests);
}
return err;
}