File: fcoll_base_coll_array.c

package info (click to toggle)
openmpi 5.0.8-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 201,672 kB
  • sloc: ansic: 613,078; makefile: 42,354; sh: 11,194; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,179; python: 1,859; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (500 lines) | stat: -rw-r--r-- 17,098 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*
 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
 *                         University Research and Technology
 *                         Corporation.  All rights reserved.
 * Copyright (c) 2004-2007 The University of Tennessee and The University
 *                         of Tennessee Research Foundation.  All rights
 *                         reserved.
 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
 *                         University of Stuttgart.  All rights reserved.
 * Copyright (c) 2004-2005 The Regents of the University of California.
 *                         All rights reserved.
 * Copyright (c) 2008-2016 University of Houston. All rights reserved.
 * Copyright (c) 2017      Research Organization for Information Science
 *                         and Technology (RIST). All rights reserved.
 * Copyright (c) 2017      IBM Corporation. All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "ompi_config.h"

#include "ompi/runtime/params.h"
#include "ompi/communicator/communicator.h"
#include "ompi/mca/pml/pml.h"
#include "opal/datatype/opal_datatype.h"
#include "ompi/datatype/ompi_datatype.h"
#include "ompi/request/request.h"

#include <math.h>
#include "ompi/mca/fcoll/base/fcoll_base_coll_array.h"
#include "ompi/mca/common/ompio/common_ompio.h"


int ompi_fcoll_base_coll_allgatherv_array (void *sbuf,
                                      int scount,
                                      ompi_datatype_t *sdtype,
                                      void *rbuf,
                                      int *rcounts,
                                      int *disps,
                                      ompi_datatype_t *rdtype,
                                      int root_index,
                                      int *procs_in_group,
                                      int procs_per_group,
                                      ompi_communicator_t *comm)
{
    int err = OMPI_SUCCESS;
    ptrdiff_t extent, lb;
    int i, rank, j;
    char *send_buf = NULL;
    struct ompi_datatype_t *newtype, *send_type;

    rank = ompi_comm_rank (comm);
    for (j = 0; j < procs_per_group; j++) {
        if (procs_in_group[j] == rank) {
            break;
        }
    }

    if (MPI_IN_PLACE == sbuf) {
        err = opal_datatype_get_extent (&rdtype->super, &lb, &extent);
        if (OMPI_SUCCESS != err) {
            return OMPI_ERROR;
        }
        send_type = rdtype;
        send_buf = (char*)rbuf;

        for (i = 0; i < j; i++) {
            send_buf += (rcounts[i] * extent);
        }
    }
    else {
        send_buf = (char*)sbuf;
        send_type = sdtype;
    }

    err = ompi_fcoll_base_coll_gatherv_array (send_buf,
                                         rcounts[j],
                                         send_type,
                                         rbuf,
                                         rcounts,
                                         disps,
                                         rdtype,
                                         root_index,
                                         procs_in_group,
                                         procs_per_group,
                                         comm);
    if (OMPI_SUCCESS != err) {
        return err;
    }

    err = ompi_datatype_create_indexed (procs_per_group,
                                        rcounts,
                                        disps,
                                        rdtype,
                                        &newtype);
    if (MPI_SUCCESS != err) {
        return err;
    }
    err = ompi_datatype_commit (&newtype);
    if(MPI_SUCCESS != err) {
        return err;
    }
    
    ompi_fcoll_base_coll_bcast_array (rbuf,
                                 1,
                                 newtype,
                                 root_index,
                                 procs_in_group,
                                 procs_per_group,
                                 comm);
    
    ompi_datatype_destroy (&newtype);

    return OMPI_SUCCESS;
}

int ompi_fcoll_base_coll_gatherv_array (void *sbuf,
                                   int scount,
                                   ompi_datatype_t *sdtype,
                                   void *rbuf,
                                   int *rcounts,
                                   int *disps,
                                   ompi_datatype_t *rdtype,
                                   int root_index,
                                   int *procs_in_group,
                                   int procs_per_group,
                                   struct ompi_communicator_t *comm)
{
    int i, rank;
    int err = OMPI_SUCCESS;
    char *ptmp;
    ptrdiff_t extent, lb;
    ompi_request_t **reqs=NULL;

    rank = ompi_comm_rank (comm);

    if (procs_in_group[root_index] != rank)  {
        if (scount > 0) {
            return MCA_PML_CALL(send(sbuf,
                                     scount,
                                     sdtype,
                                     procs_in_group[root_index],
                                     FCOLL_TAG_GATHERV,
                                     MCA_PML_BASE_SEND_STANDARD,
                                     comm));
        }
        return err;
    }

    /* writer processes, loop receiving data from processes
       belonging to each corresponding root */

    err = opal_datatype_get_extent (&rdtype->super, &lb, &extent);
    if (OMPI_SUCCESS != err) {
        return OMPI_ERROR;
    }
    reqs = (ompi_request_t **) malloc ( procs_per_group *sizeof(ompi_request_t *));
    if ( NULL == reqs ) {
	return OMPI_ERR_OUT_OF_RESOURCE;
    }
    for (i=0; i<procs_per_group; i++) {
        ptmp = ((char *) rbuf) + (extent * disps[i]);

        if (procs_in_group[i] == rank) {
            if (MPI_IN_PLACE != sbuf &&
                (0 < scount) &&
                (0 < rcounts[i])) {
                err = ompi_datatype_sndrcv (sbuf,
                                            scount,
                                            sdtype,
                                            ptmp,
                                            rcounts[i],
                                            rdtype);
            }
	    reqs[i] = MPI_REQUEST_NULL;
        }
        else {
            /* Only receive if there is something to receive */
            if (rcounts[i] > 0) {
                err = MCA_PML_CALL(irecv(ptmp,
                                         rcounts[i],
                                         rdtype,
                                         procs_in_group[i],
                                         FCOLL_TAG_GATHERV,
                                         comm,
                                         &reqs[i]));
            }
	    else {
		reqs[i] = MPI_REQUEST_NULL;
	    }
        }

        if (OMPI_SUCCESS != err) {
	    free ( reqs );
            return err;
        }
    }
    /* All done */
    err = ompi_request_wait_all ( procs_per_group, reqs, MPI_STATUSES_IGNORE );
    if ( NULL != reqs ) {
	free ( reqs );
    }
    return err;
}

int ompi_fcoll_base_coll_scatterv_array (void *sbuf,
                                    int *scounts,
                                    int *disps,
                                    ompi_datatype_t *sdtype,
                                    void *rbuf,
                                    int rcount,
                                    ompi_datatype_t *rdtype,
                                    int root_index,
                                    int *procs_in_group,
                                    int procs_per_group,
                                    struct ompi_communicator_t *comm)
{
    int i, rank;
    int err = OMPI_SUCCESS;
    char *ptmp;
    ptrdiff_t extent, lb;
    ompi_request_t ** reqs=NULL;

    rank = ompi_comm_rank (comm);

    if (procs_in_group[root_index] != rank) {
        if (rcount > 0) {
            err = MCA_PML_CALL(recv(rbuf,
                                    rcount,
                                    rdtype,
                                    procs_in_group[root_index],
                                    FCOLL_TAG_SCATTERV,
                                    comm,
                                    MPI_STATUS_IGNORE));
        }
        return err;
    }

    /* writer processes, loop sending data to processes
       belonging to each corresponding root */

    err = opal_datatype_get_extent (&sdtype->super, &lb, &extent);
    if (OMPI_SUCCESS != err) {
        return OMPI_ERROR;
    }
    reqs = ( ompi_request_t **) malloc ( procs_per_group * sizeof ( ompi_request_t *));
    if (NULL == reqs ) {
	return OMPI_ERR_OUT_OF_RESOURCE;
    }

    for (i=0 ; i<procs_per_group ; ++i) {
        ptmp = ((char *) sbuf) + (extent * disps[i]);

        if (procs_in_group[i] == rank) {
            if (MPI_IN_PLACE != sbuf &&
                (0 < scounts[i]) &&
                (0 < rcount)) {
                err = ompi_datatype_sndrcv (ptmp,
                                            scounts[i],
                                            sdtype,
                                            rbuf,
                                            rcount,
                                            rdtype);
            }
	    reqs[i] = MPI_REQUEST_NULL;
        }
        else {
            /* Only receive if there is something to receive */
            if (scounts[i] > 0) {
                err = MCA_PML_CALL(isend(ptmp,
                                         scounts[i],
                                         sdtype,
                                         procs_in_group[i],
                                         FCOLL_TAG_SCATTERV,
                                         MCA_PML_BASE_SEND_STANDARD,
                                         comm,
				         &reqs[i]));
            }
	    else {
		reqs[i] = MPI_REQUEST_NULL;
            }
        }
        if (OMPI_SUCCESS != err) {
            free ( reqs );
            return err;
        }
    }
    /* All done */
    err = ompi_request_wait_all ( procs_per_group, reqs, MPI_STATUSES_IGNORE );
    if ( NULL != reqs ) {
	free ( reqs );
    }
    return err;
}

int ompi_fcoll_base_coll_allgather_array (void *sbuf,
                                     int scount,
                                     ompi_datatype_t *sdtype,
                                     void *rbuf,
                                     int rcount,
                                     ompi_datatype_t *rdtype,
                                     int root_index,
                                     int *procs_in_group,
                                     int procs_per_group,
                                     ompi_communicator_t *comm)
{
    int err = OMPI_SUCCESS;
    int rank;
    ptrdiff_t extent, lb;

    rank = ompi_comm_rank (comm);

    if (((void *) 1) == sbuf && 0 != rank) {
        err = opal_datatype_get_extent (&rdtype->super, &lb, &extent);
        if (OMPI_SUCCESS != err) {
            return OMPI_ERROR;
        }
        sbuf = ((char*) rbuf) + (rank * extent * rcount);
        sdtype = rdtype;
        scount = rcount;
    }

    /* Gather and broadcast. */
    err = ompi_fcoll_base_coll_gather_array (sbuf,
                                        scount,
                                        sdtype,
                                        rbuf,
                                        rcount,
                                        rdtype,
                                        root_index,
                                        procs_in_group,
                                        procs_per_group,
                                        comm);
    
    if (OMPI_SUCCESS == err) {
        err = ompi_fcoll_base_coll_bcast_array (rbuf,
                                           rcount * procs_per_group,
                                           rdtype,
                                           root_index,
                                           procs_in_group,
                                           procs_per_group,
                                           comm);
    }
    /* All done */

    return err;
}

int ompi_fcoll_base_coll_gather_array (void *sbuf,
                                  int scount,
                                  ompi_datatype_t *sdtype,
                                  void *rbuf,
                                  int rcount,
                                  ompi_datatype_t *rdtype,
                                  int root_index,
                                  int *procs_in_group,
                                  int procs_per_group,
                                  struct ompi_communicator_t *comm)
{
    int i;
    int rank;
    char *ptmp;
    ptrdiff_t incr;
    ptrdiff_t extent, lb;
    int err = OMPI_SUCCESS;
    ompi_request_t ** reqs=NULL;

    rank = ompi_comm_rank (comm);

    /* Everyone but the writers sends data and returns. */
    if (procs_in_group[root_index] != rank) {
        err = MCA_PML_CALL(send(sbuf,
                                scount,
                                sdtype,
                                procs_in_group[root_index],
                                FCOLL_TAG_GATHER,
                                MCA_PML_BASE_SEND_STANDARD,
                                comm));
        return err;
    }

    /* writers, loop receiving the data. */
    opal_datatype_get_extent (&rdtype->super, &lb, &extent);
    incr = extent * rcount;

    reqs = ( ompi_request_t **) malloc ( procs_per_group * sizeof ( ompi_request_t *));
    if (NULL == reqs ) {
	return OMPI_ERR_OUT_OF_RESOURCE;
    }

    for (i = 0, ptmp = (char *) rbuf;
         i < procs_per_group;
         ++i, ptmp += incr) {
        if (procs_in_group[i] == rank) {
            if (MPI_IN_PLACE != sbuf) {
                err = ompi_datatype_sndrcv (sbuf,
                                            scount,
                                            sdtype ,
                                            ptmp,
                                            rcount,
                                            rdtype);
            }
            else {
                err = OMPI_SUCCESS;
            }
	    reqs[i] = MPI_REQUEST_NULL;
        }
        else {
            err = MCA_PML_CALL(irecv(ptmp,
                                     rcount,
                                     rdtype,
                                     procs_in_group[i],
                                     FCOLL_TAG_GATHER,
                                     comm,
                                     &reqs[i]));
            /*
            for (k=0 ; k<4 ; k++)
                printf ("RECV %p  %d \n",
                        ((struct iovec *)ptmp)[k].iov_base,
                        ((struct iovec *)ptmp)[k].iov_len);
            */
        }

        if (OMPI_SUCCESS != err) {
	    free ( reqs );
            return err;
        }
    }

    /* All done */
    err = ompi_request_wait_all ( procs_per_group, reqs, MPI_STATUSES_IGNORE );
    if ( NULL != reqs ) {
	free ( reqs );
    }

    return err;
}

int ompi_fcoll_base_coll_bcast_array (void *buff,
                                 int count,
                                 ompi_datatype_t *datatype,
                                 int root_index,
                                 int *procs_in_group,
                                 int procs_per_group,
                                 ompi_communicator_t *comm)
{
    int i, rank;
    int err = OMPI_SUCCESS;
    ompi_request_t ** reqs=NULL;

    rank = ompi_comm_rank (comm);

    /* Non-writers receive the data. */
    if (procs_in_group[root_index] != rank) {
        err = MCA_PML_CALL(recv(buff,
                                count,
                                datatype,
                                procs_in_group[root_index],
                                FCOLL_TAG_BCAST,
                                comm,
                                MPI_STATUS_IGNORE));
        return err;
    }

    /* Writers sends data to all others. */
    reqs = ( ompi_request_t **) malloc ( procs_per_group * sizeof ( ompi_request_t *));
    if (NULL == reqs ) {
	return OMPI_ERR_OUT_OF_RESOURCE;
    }

    for (i=0 ; i<procs_per_group ; i++) {
        if (procs_in_group[i] == rank) {
	    reqs[i] = MPI_REQUEST_NULL;
            continue;
        }

        err = MCA_PML_CALL(isend(buff,
                                 count,
                                 datatype,
                                 procs_in_group[i],
                                 FCOLL_TAG_BCAST,
                                 MCA_PML_BASE_SEND_STANDARD,
                                 comm,
			         &reqs[i]));
        if (OMPI_SUCCESS != err) {
	    free ( reqs );
            return err;
        }
    }
    err = ompi_request_wait_all ( procs_per_group, reqs, MPI_STATUSES_IGNORE );
    if ( NULL != reqs ) {
	free ( reqs );
    }

    return err;
}