coll_tuned_bcast.c
来自「MPI stands for the Message Passing Inter」· C语言 代码 · 共 789 行 · 第 1/3 页
C
789 行
/* Step 2: Find your immediate pair (identical node in opposite subtree) and SendRecv data buffer with them. The tree building function ensures that if (we are not root) if we are in the left subtree (lr == 0) our pair is (rank+1)%size. if we are in the right subtree (lr == 1) our pair is (rank-1)%size If we have even number of nodes the rank (size-1) will pair up with root. */ if (lr == 0) { pair = (rank+1)%size; } else { pair = (rank+size-1)%size; } if ( (size%2) != 0 && rank != root) { err = ompi_coll_tuned_sendrecv( tmpbuf[lr], counts[lr], datatype, pair, MCA_COLL_BASE_TAG_BCAST, tmpbuf[(lr+1)%2], counts[(lr+1)%2], datatype, pair, MCA_COLL_BASE_TAG_BCAST, comm, MPI_STATUS_IGNORE, rank); if (err != MPI_SUCCESS) { line = __LINE__; goto error_hndl; } } else if ( (size%2) == 0 ) { /* root sends right buffer to the last node */ if( rank == root ) { MCA_PML_CALL(send(tmpbuf[1], counts[1], datatype, (root+size-1)%size, MCA_COLL_BASE_TAG_BCAST, MCA_PML_BASE_SEND_STANDARD, comm)); if (err != MPI_SUCCESS) { line = __LINE__; goto error_hndl; } } /* last node receives right buffer from the root */ else if (rank == (root+size-1)%size) { MCA_PML_CALL(recv(tmpbuf[1], counts[1], datatype, root, MCA_COLL_BASE_TAG_BCAST, comm, MPI_STATUS_IGNORE)); if (err != MPI_SUCCESS) { line = __LINE__; goto error_hndl; } } /* everyone else exchanges buffers */ else { err = ompi_coll_tuned_sendrecv( tmpbuf[lr], counts[lr], datatype, pair, MCA_COLL_BASE_TAG_BCAST, tmpbuf[(lr+1)%2], counts[(lr+1)%2], datatype, pair, MCA_COLL_BASE_TAG_BCAST, comm, MPI_STATUS_IGNORE, rank); if (err != MPI_SUCCESS) { line = __LINE__; goto error_hndl; } } } return (MPI_SUCCESS); error_hndl: OPAL_OUTPUT((ompi_coll_tuned_stream,"%s:%4d\tError occurred %d, rank %2d", __FILE__,line,err,rank)); return (err);}/* * Linear functions are copied from the BASIC coll module * they do not segment the message and are simple implementations * but for some small number of nodes and/or small data sizes they * are just as fast as tuned/tree based segmenting operations * and as such may be selected by the decision functions * These are copied into this module due to the way we select modules * in V1. i.e. in V2 we will handle this differently and so will not * have to duplicate code. * GEF Oct05 after asking Jeff. *//* copied function (with appropriate renaming) starts here *//* * bcast_lin_intra * * Function: - broadcast using O(N) algorithm * Accepts: - same arguments as MPI_Bcast() * Returns: - MPI_SUCCESS or error code */intompi_coll_tuned_bcast_intra_basic_linear (void *buff, int count, struct ompi_datatype_t *datatype, int root, struct ompi_communicator_t *comm){ int i; int size; int rank; int err; ompi_request_t **preq; ompi_request_t **reqs = comm->c_coll_selected_data->mcct_reqs; size = ompi_comm_size(comm); rank = ompi_comm_rank(comm); OPAL_OUTPUT((ompi_coll_tuned_stream,"ompi_coll_tuned_bcast_intra_basic_linear rank %d root %d", rank, root)); /* Non-root receive the data. */ if (rank != root) { return MCA_PML_CALL(recv(buff, count, datatype, root, MCA_COLL_BASE_TAG_BCAST, comm, MPI_STATUS_IGNORE)); } /* Root sends data to all others. */ for (i = 0, preq = reqs; i < size; ++i) { if (i == rank) { continue; } err = MCA_PML_CALL(isend_init(buff, count, datatype, i, MCA_COLL_BASE_TAG_BCAST, MCA_PML_BASE_SEND_STANDARD, comm, preq++)); if (MPI_SUCCESS != err) { return err; } } --i; /* Start your engines. This will never return an error. */ MCA_PML_CALL(start(i, reqs)); /* Wait for them all. If there's an error, note that we don't * care what the error was -- just that there *was* an error. The * PML will finish all requests, even if one or more of them fail. * i.e., by the end of this call, all the requests are free-able. * So free them anyway -- even if there was an error, and return * the error after we free everything. */ err = ompi_request_wait_all(i, reqs, MPI_STATUSES_IGNORE); /* Free the reqs */ ompi_coll_tuned_free_reqs(reqs, i); /* All done */ return err;}/* copied function (with appropriate renaming) ends here *//* The following are used by dynamic and forced rules *//* publish details of each algorithm and if its forced/fixed/locked in *//* as you add methods/algorithms you must update this and the query/map routines *//* this routine is called by the component only *//* this makes sure that the mca parameters are set to their initial values and perms *//* module does not call this they call the forced_getvalues routine instead */int ompi_coll_tuned_bcast_intra_check_forced_init (coll_tuned_force_algorithm_mca_param_indices_t *mca_param_indices){ int rc, max_alg = 6, requested_alg; ompi_coll_tuned_forced_max_algorithms[BCAST] = max_alg; rc = mca_base_param_reg_int (&mca_coll_tuned_component.super.collm_version, "bcast_algorithm_count", "Number of bcast algorithms available", false, true, max_alg, NULL); mca_param_indices->algorithm_param_index = mca_base_param_reg_int(&mca_coll_tuned_component.super.collm_version, "bcast_algorithm", "Which bcast algorithm is used. Can be locked down to choice of: 0 ignore, 1 basic linear, 2 chain, 3: pipeline, 4: split binary tree, 5: binary tree, 6: binomial tree.", false, false, 0, NULL); mca_base_param_lookup_int(mca_param_indices->algorithm_param_index, &(requested_alg)); if( requested_alg > max_alg ) { if( 0 == ompi_comm_rank( MPI_COMM_WORLD ) ) { opal_output( 0, "Broadcast algorithm #%d is not available (range [0..%d]). Switching back to ignore(0)\n", requested_alg, max_alg ); } mca_base_param_set_int( mca_param_indices->algorithm_param_index, 0); } mca_param_indices->segsize_param_index = mca_base_param_reg_int(&mca_coll_tuned_component.super.collm_version, "bcast_algorithm_segmentsize", "Segment size in bytes used by default for bcast algorithms. Only has meaning if algorithm is forced and supports segmenting. 0 bytes means no segmentation.", false, false, 0, NULL); mca_param_indices->tree_fanout_param_index = mca_base_param_reg_int(&mca_coll_tuned_component.super.collm_version, "bcast_algorithm_tree_fanout", "Fanout for n-tree used for bcast algorithms. Only has meaning if algorithm is forced and supports n-tree topo based operation.", false, false, ompi_coll_tuned_init_tree_fanout, /* get system wide default */ NULL); mca_param_indices->chain_fanout_param_index = mca_base_param_reg_int(&mca_coll_tuned_component.super.collm_version, "bcast_algorithm_chain_fanout", "Fanout for chains used for bcast algorithms. Only has meaning if algorithm is forced and supports chain topo based operation.", false, false, ompi_coll_tuned_init_chain_fanout, /* get system wide default */ NULL); return (MPI_SUCCESS);}int ompi_coll_tuned_bcast_intra_do_forced(void *buf, int count, struct ompi_datatype_t *dtype, int root, struct ompi_communicator_t *comm){ OPAL_OUTPUT((ompi_coll_tuned_stream,"coll:tuned:bcast_intra_do_forced algorithm %d", comm->c_coll_selected_data->user_forced[BCAST].algorithm)); switch (comm->c_coll_selected_data->user_forced[BCAST].algorithm) { case (0): return ompi_coll_tuned_bcast_intra_dec_fixed( buf, count, dtype, root, comm ); case (1): return ompi_coll_tuned_bcast_intra_basic_linear( buf, count, dtype, root, comm ); case (2): return ompi_coll_tuned_bcast_intra_chain( buf, count, dtype, root, comm, comm->c_coll_selected_data->user_forced[BCAST].segsize, comm->c_coll_selected_data->user_forced[BCAST].chain_fanout ); case (3): return ompi_coll_tuned_bcast_intra_pipeline( buf, count, dtype, root, comm, comm->c_coll_selected_data->user_forced[BCAST].segsize ); case (4): return ompi_coll_tuned_bcast_intra_split_bintree( buf, count, dtype, root, comm, comm->c_coll_selected_data->user_forced[BCAST].segsize ); case (5): return ompi_coll_tuned_bcast_intra_bintree( buf, count, dtype, root, comm, comm->c_coll_selected_data->user_forced[BCAST].segsize ); case (6): return ompi_coll_tuned_bcast_intra_binomial( buf, count, dtype, root, comm, comm->c_coll_selected_data->user_forced[BCAST].segsize ); default: OPAL_OUTPUT((ompi_coll_tuned_stream,"coll:tuned:bcast_intra_do_forced attempt to select algorithm %d when only 0-%d is valid?", comm->c_coll_selected_data->user_forced[BCAST].algorithm, ompi_coll_tuned_forced_max_algorithms[BCAST])); } /* switch */ return (MPI_ERR_ARG);}int ompi_coll_tuned_bcast_intra_do_this(void *buf, int count, struct ompi_datatype_t *dtype, int root, struct ompi_communicator_t *comm, int algorithm, int faninout, int segsize){ OPAL_OUTPUT((ompi_coll_tuned_stream,"coll:tuned:bcast_intra_do_this algorithm %d topo faninout %d segsize %d", algorithm, faninout, segsize)); switch (algorithm) { case (0): return ompi_coll_tuned_bcast_intra_dec_fixed( buf, count, dtype, root, comm ); case (1): return ompi_coll_tuned_bcast_intra_basic_linear( buf, count, dtype, root, comm ); case (2): return ompi_coll_tuned_bcast_intra_chain( buf, count, dtype, root, comm, segsize, faninout ); case (3): return ompi_coll_tuned_bcast_intra_pipeline( buf, count, dtype, root, comm, segsize ); case (4): return ompi_coll_tuned_bcast_intra_split_bintree( buf, count, dtype, root, comm, segsize ); case (5): return ompi_coll_tuned_bcast_intra_bintree( buf, count, dtype, root, comm, segsize ); case (6): return ompi_coll_tuned_bcast_intra_binomial( buf, count, dtype, root, comm, segsize ); default: OPAL_OUTPUT((ompi_coll_tuned_stream,"coll:tuned:bcast_intra_do_this attempt to select algorithm %d when only 0-%d is valid?", algorithm, ompi_coll_tuned_forced_max_algorithms[BCAST])); } /* switch */ return (MPI_ERR_ARG);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?