1 /* Copyright (C) 2012-2014 Free Software Foundation, Inc.
2 This file is part of the UPC runtime library.
3 Written by Gary Funck <gary@intrepid.com>
4 and Nenad Vukicevic <nenad@intrepid.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. */
27 /*****************************************************************************/
29 /* Copyright (c) 2004, Michigan Technological University */
30 /* All rights reserved. */
32 /* Redistribution and use in source and binary forms, with or without */
33 /* modification, are permitted provided that the following conditions */
36 /* * Redistributions of source code must retain the above copyright */
37 /* notice, this list of conditions and the following disclaimer. */
38 /* * Redistributions in binary form must reproduce the above */
39 /* copyright notice, this list of conditions and the following */
40 /* disclaimer in the documentation and/or other materials provided */
41 /* with the distribution. */
42 /* * Neither the name of the Michigan Technological University */
43 /* nor the names of its contributors may be used to endorse or promote */
44 /* products derived from this software without specific prior written */
47 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
48 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
49 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A */
50 /* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER */
51 /* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
52 /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, */
53 /* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR */
54 /* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
55 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
56 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
57 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
59 /*****************************************************************************/
62 #include <upc_collective.h>
65 /*****************************************************************************/
67 /* UPC collective function library, reference implementation */
69 /* Steve Seidel, Dept. of Computer Science, Michigan Technological Univ. */
70 /* steve@mtu.edu March 1, 2004 */
72 /*****************************************************************************/
75 upc_all_gather (shared void *dst,
76 shared const void *src, size_t nbytes, upc_flag_t sync_mode)
87 if (!upc_coll_init_flag)
90 #ifdef _UPC_COLL_CHECK_ARGS
91 upc_coll_err (dst, src, NULL, nbytes, sync_mode, 0, 0, 0, UPC_GATH);
93 // Synchronize using barriers in the cases of MYSYNC and ALLSYNC.
95 if (UPC_IN_MYSYNC & sync_mode || !(UPC_IN_NOSYNC & sync_mode))
101 // The dst thread "pulls" a block of data from each src thread.
103 if ((int)upc_threadof ((shared void *) dst) == MYTHREAD)
105 for (i = 0; i < THREADS; ++i)
107 upc_memcpy ((shared char *) dst + nbytes * i * THREADS,
108 (shared char *) src + i, nbytes);
115 // Each src thread "pushes" the data to the dst thread.
117 upc_memcpy ((shared char *) dst + MYTHREAD * THREADS * nbytes,
118 (shared char *) src + MYTHREAD, nbytes);
122 // Synchronize using barriers in the cases of MYSYNC and ALLSYNC.
124 if (UPC_OUT_MYSYNC & sync_mode || !(UPC_OUT_NOSYNC & sync_mode))