|
| 1 | +/* |
| 2 | + * Copyright (c) 2016 Mellanox Technologies, Inc. |
| 3 | + * All rights reserved. |
| 4 | + * $COPYRIGHT$ |
| 5 | + * |
| 6 | + * Additional copyrights may follow |
| 7 | + * |
| 8 | + * $HEADER$ |
| 9 | + */ |
| 10 | + |
| 11 | +#include "oshmem_config.h" |
| 12 | +#include <stdio.h> |
| 13 | +#include <stdlib.h> |
| 14 | + |
| 15 | +#include "oshmem/constants.h" |
| 16 | +#include "oshmem/op/op.h" |
| 17 | +#include "oshmem/mca/spml/spml.h" |
| 18 | +#include "oshmem/mca/scoll/scoll.h" |
| 19 | +#include "oshmem/mca/scoll/base/base.h" |
| 20 | +#include "scoll_basic.h" |
| 21 | + |
| 22 | +static int _algorithm_simple(struct oshmem_group_t *group, |
| 23 | + void *target, |
| 24 | + const void *source, |
| 25 | + ptrdiff_t dst, ptrdiff_t sst, |
| 26 | + size_t nelems, |
| 27 | + size_t element_size, |
| 28 | + long *pSync); |
| 29 | + |
| 30 | +int mca_scoll_basic_alltoall(struct oshmem_group_t *group, |
| 31 | + void *target, |
| 32 | + const void *source, |
| 33 | + ptrdiff_t dst, ptrdiff_t sst, |
| 34 | + size_t nelems, |
| 35 | + size_t element_size, |
| 36 | + long *pSync, |
| 37 | + int alg) |
| 38 | +{ |
| 39 | + int rc = OSHMEM_SUCCESS; |
| 40 | + |
| 41 | + /* Arguments validation */ |
| 42 | + if (!group) { |
| 43 | + SCOLL_ERROR("Active set (group) of PE is not defined"); |
| 44 | + rc = OSHMEM_ERR_BAD_PARAM; |
| 45 | + } |
| 46 | + |
| 47 | + /* Check if this PE is part of the group */ |
| 48 | + if ((rc == OSHMEM_SUCCESS) && oshmem_proc_group_is_member(group)) { |
| 49 | + int i = 0; |
| 50 | + |
| 51 | + if (pSync) { |
| 52 | + rc = _algorithm_simple(group, |
| 53 | + target, |
| 54 | + source, |
| 55 | + dst, |
| 56 | + sst, |
| 57 | + nelems, |
| 58 | + element_size, |
| 59 | + pSync); |
| 60 | + } else { |
| 61 | + SCOLL_ERROR("Incorrect argument pSync"); |
| 62 | + rc = OSHMEM_ERR_BAD_PARAM; |
| 63 | + } |
| 64 | + |
| 65 | + /* Restore initial values */ |
| 66 | + SCOLL_VERBOSE(12, |
| 67 | + "PE#%d Restore special synchronization array", |
| 68 | + group->my_pe); |
| 69 | + for (i = 0; pSync && (i < _SHMEM_ALLTOALL_SYNC_SIZE); i++) { |
| 70 | + pSync[i] = _SHMEM_SYNC_VALUE; |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + return rc; |
| 75 | +} |
| 76 | + |
| 77 | +static int _algorithm_simple(struct oshmem_group_t *group, |
| 78 | + void *target, |
| 79 | + const void *source, |
| 80 | + ptrdiff_t tst, ptrdiff_t sst, |
| 81 | + size_t nelems, |
| 82 | + size_t element_size, |
| 83 | + long *pSync) |
| 84 | +{ |
| 85 | + int rc = OSHMEM_SUCCESS; |
| 86 | + int pe_cur; |
| 87 | + int i; |
| 88 | + int j; |
| 89 | + int k; |
| 90 | + |
| 91 | + SCOLL_VERBOSE(14, |
| 92 | + "[#%d] send data to all PE in the group", |
| 93 | + group->my_pe); |
| 94 | + j = oshmem_proc_group_find_id(group, group->my_pe); |
| 95 | + for (i = 0; i < group->proc_count; i++) { |
| 96 | + /* index permutation for better distribution of traffic */ |
| 97 | + k = (((j)+(i))%(group->proc_count)); |
| 98 | + pe_cur = oshmem_proc_pe(group->proc_array[k]); |
| 99 | + rc = MCA_SPML_CALL(put( |
| 100 | + (void *)((char *)target + j * tst * nelems * element_size), |
| 101 | + nelems * element_size, |
| 102 | + (void *)((char *)source + i * sst * nelems * element_size), |
| 103 | + pe_cur)); |
| 104 | + if (OSHMEM_SUCCESS != rc) { |
| 105 | + break; |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + /* Wait for operation completion */ |
| 110 | + if (rc == OSHMEM_SUCCESS) { |
| 111 | + SCOLL_VERBOSE(14, "[#%d] Wait for operation completion", group->my_pe); |
| 112 | + rc = BARRIER_FUNC(group, |
| 113 | + (pSync + 1), |
| 114 | + SCOLL_DEFAULT_ALG); |
| 115 | + } |
| 116 | + |
| 117 | + return rc; |
| 118 | +} |
0 commit comments