2 This source code file is part of thread_mpi.
3 Written by Sander Pronk, Erik Lindahl, and possibly others.
5 Copyright (c) 2009, Sander Pronk, Erik Lindahl.
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 1) Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2) Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15 3) Neither the name of the copyright holders nor the
16 names of its contributors may be used to endorse or promote products
17 derived from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY US ''AS IS'' AND ANY
20 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL WE BE LIABLE FOR ANY
23 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 If you want to redistribute modifications, please consider that
31 scientific software is very special. Version control is crucial -
32 bugs must be traceable. We will be happy to consider code for
33 inclusion in the official distribution, but derived work should not
34 be called official thread_mpi. Details are found in the README & COPYING
43 * \brief Partial implementation of MPI using only threads.
45 * See the MPI specification at
46 * http://www.mpi-forum.org/docs/docs.html
47 * for an explanation of what these functions do.
49 * Because this is a thread-based library, be very careful with global
50 * variables and static variables in functions: they will be shared across
51 * all threads and lead to conflicts if not properly mutex-ed or barrier-ed
54 * \sa http://www.mpi-forum.org/docs/docs.html for MPI documentation.
63 } /* Avoids screwing up auto-indentation */
68 Use this to check for thread_mpi with the preprocessor. */
75 Holds the group of processes to communicate
76 with, and defines the scope for global operations such as broadcast. */
77 typedef struct tmpi_comm_ *tMPI_Comm;
81 The group structure. Contains a list of threads. */
82 typedef struct tmpi_group_ *tMPI_Group;
86 Request structure for holding data about non-blocking transfers. */
87 typedef struct tmpi_req_ *tMPI_Request;
92 tMPI data type structure. Holds info about datatypes. */
93 typedef struct tmpi_datatype_ *tMPI_Datatype;
96 /*! \name tMPI Data types
97 These are MPI data types as specified by the MPI standard.
98 Note that not all are available. */
100 extern const tMPI_Datatype TMPI_CHAR; /**< char */
101 extern const tMPI_Datatype TMPI_SHORT; /**< short */
102 extern const tMPI_Datatype TMPI_INT; /**< int */
103 extern const tMPI_Datatype TMPI_LONG; /**< long */
104 #ifdef SIZEOF_LONG_LONG_INT
105 extern const tMPI_Datatype TMPI_LONG_LONG; /**< long long */
106 extern const tMPI_Datatype TMPI_LONG_LONG_INT; /**< long long int */
108 extern const tMPI_Datatype TMPI_SIGNED_CHAR; /**< signed char */
109 extern const tMPI_Datatype TMPI_UNSIGNED_CHAR; /**< unsigned char */
110 extern const tMPI_Datatype TMPI_UNSIGNED_SHORT; /**< unsigned short */
111 extern const tMPI_Datatype TMPI_UNSIGNED; /**< unsigned int */
112 extern const tMPI_Datatype TMPI_UNSIGNED_LONG; /**< unsigned long */
113 #ifdef SIZEOF_LONG_LONG_INT
114 extern const tMPI_Datatype TMPI_UNSIGNED_LONG_LONG; /**< unsigned long long */
116 extern const tMPI_Datatype TMPI_FLOAT; /**< float */
117 extern const tMPI_Datatype TMPI_DOUBLE; /**< double */
118 extern const tMPI_Datatype TMPI_LONG_DOUBLE; /**< long double */
119 /*extern tMPI_Datatype tMPI_UNSIGNED_WCHAR */
120 extern const tMPI_Datatype TMPI_BYTE; /**< byte (for binary
122 extern const tMPI_Datatype TMPI_POINTER; /**< pointer (thread_mpi
131 TMPI_SUCCESS=0, /*!< No error */
132 TMPI_ERR_MALLOC, /*!< Out of memory */
133 TMPI_ERR_INIT, /*!< Initialization error */
134 TMPI_ERR_FINALIZE, /*!< Finalize error */
135 TMPI_ERR_GROUP, /*!< Group error */
136 TMPI_ERR_COMM, /*!< Comm error */
137 TMPI_ERR_STATUS, /*!< Status error */
138 TMPI_ERR_GROUP_RANK, /*!< Group rank error */
141 TMPI_ERR_CART_CREATE_NPROCS,
142 TMPI_ERR_XFER_COUNTERPART,
143 TMPI_ERR_XFER_BUFSIZE,
144 TMPI_ERR_XFER_BUF_OVERLAP,
148 TMPI_ERR_MULTI_MISMATCH,
155 N_TMPI_ERR /* this must be the last one */
158 /** Maximum length of error string for tMPI_Error_string() */
159 #define TMPI_MAX_ERROR_STRING 256
161 /** default code for undefined value,
163 For example for undefined color in tMPI_Split(). */
164 #define TMPI_UNDEFINED -1
166 /** error handler function */
167 typedef void (*tMPI_Errhandler_fn)(tMPI_Comm*, int*);
168 /** error handler object */
169 typedef struct tmpi_errhandler_ *tMPI_Errhandler;
171 /** pre-defined error handler that abort()s on every error */
172 extern tMPI_Errhandler TMPI_ERRORS_ARE_FATAL;
173 /** pre-defined error handler that tries to continue on every error */
174 extern tMPI_Errhandler TMPI_ERRORS_RETURN;
176 /*! \name tMPI_Comm_compare() return codes */
178 /** Identical comms*/
180 /** Comms with the same members in the same order*/
181 #define TMPI_CONGRUENT 1
182 /** Comms with the same members in the different order*/
183 #define TMPI_SIMILAR 2
184 /** Comms with the different members */
185 #define TMPI_UNEQUAL 3
189 /** Source number wildcard so tMPI_Recv(), etc. can receive from
191 #define TMPI_ANY_SOURCE -1
192 /** Tag number wildcard so tMPI_Recv(), etc. can receive messages with
194 #define TMPI_ANY_TAG -1
196 /** Return code for Cartesian topology with tMPI_Topo_test(). */
198 /** Return code for graph topology with tMPI_Topo_test(). */
202 /** Pre-initialized communicator with all available threads. */
203 extern tMPI_Comm TMPI_COMM_WORLD;
206 /** A pre-defined NULL communicator to compare against, to check comm
208 #define TMPI_COMM_NULL NULL
209 /** A pre-defined NULL group to compare against, to check group
211 #define TMPI_GROUP_NULL NULL
213 /** the empty group */
214 extern tMPI_Group TMPI_GROUP_EMPTY;
217 /** The maximum processor name returned using tMPI_Get_processor_name(). */
218 #define TMPI_MAX_PROCESSOR_NAME 128
221 /** Used as NULL status for tMPI_Recv(), etc. */
222 #define TMPI_STATUS_IGNORE NULL
223 /** Used as NULL status list for tMPI_Waitall(), etc. */
224 #define TMPI_STATUSES_IGNORE NULL
228 Holds status info (tag, sender, amount of data transmitted) for receives.
229 The status object is user-maintained. */
230 typedef struct tmpi_status_
232 int TMPI_SOURCE; /**< Message source rank. */
233 int TMPI_TAG; /**< Message source tag. */
234 int TMPI_ERROR; /**< Message error. */
235 size_t transferred; /**< Number of transferred bytes */
236 int cancelled; /**< Whether the transmission was canceled */
238 /*typedef struct tmpi_status_ tMPI_Status;*/
241 #define TMPI_REQUEST_NULL NULL
243 /** collective communication special to signify that the send
244 buffer is to function as receive buffer.
246 Used, for example in tMPI_Reduce. */
247 #define TMPI_IN_PLACE NULL
250 /** tMPI_Reduce operators.
252 These all work (except obviously bad combinations like bitwise
253 and/or/xor on floats, etc): */
256 TMPI_MAX, /**< calculate maximum value */
257 TMPI_MIN, /**< calculate minimum value */
258 TMPI_SUM, /**< calculate sum */
259 TMPI_PROD, /**< calculate product */
260 TMPI_LAND, /**< calculate logical and */
261 TMPI_BAND, /**< calculate binary and */
262 TMPI_LOR, /**< calculate logical or */
263 TMPI_BOR, /**< calculate binary or */
264 TMPI_LXOR, /**< calculate logical xor */
265 TMPI_BXOR /**< calculate binary xor */
269 /* function to obtain tMPI_COMM_SELF */
270 tMPI_Comm tMPI_Get_comm_self(void);
272 /** The thread-specific comm containing only the thread itself.
275 \return the self comm object associated with the thread. */
276 #define TMPI_COMM_SELF (tMPI_Get_comm_self())
286 /*! \name Initialization and exit functions
288 /** Traditional MPI initializer; spawns threads that start at
291 Seeks the argument '-nt n', where n is the number of
292 threads that will be created. If n==0, the number of threads will
293 be the recommended number of threads for this platform as obtained
294 from tMPI_Get_recommended_ntreads().
296 The new threads then run the function start_function, with the original
297 argc and argv. This function could be main(), or any other function;
298 calling this function again - whether from the started threads or from
299 the main thread - has no effect.
301 \param[in] argc argc of original main() invocation, or NULL
302 \param[in] argv argv of original main() invocation, or NULL.
303 \param[in] start_function Starting function of type
304 int start_function(int argc, char *argv[]);
306 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
307 int tMPI_Init(int *argc, char ***argv, int (*start_function)(int, char**));
310 /** Alternate thread MPI intializer and thread spawner.
312 Creates N threads (including main thread)
313 that run the function start_function, which takes a void* argument,
314 given by arg. The function start_function also gets called by the main
315 thread. When the function start_function returns it, will behave
316 as if tMPI_Finalize is called, and if it's a sub-thread it will
319 If N==0, the number of threads will be the recommended number of
320 threads for this platform as obtained from tMPI_Get_recommended_ntreads().
322 \param[in] main_thread_returns whether the control in the main thread
323 should return immediately (if true), or
324 the start_function() should be called
325 from the main thread, too (if false).
326 \param[in] N The number of threads to start (or 0 to
327 automatically determine this).
328 \param[in] start_function The function to start threads at
329 (including main thread if
330 main_thread_returns).
331 \param[in] arg An optional argument for start_function().
333 \return TMPI_FAILURE on failure, TMPI_SUCCESS on succes (after all
334 threads have finished if main_thread_returns=true). */
335 int tMPI_Init_fn(int main_thread_returns, int N,
336 void (*start_function)(void*), void *arg);
338 /** get the number of threads from the command line
340 can be called before tMPI_Init()
342 \param[in] argc argc from main()
343 \param[in] argv argv from main()
344 \param[in] optname name of the argument specifying the
345 number of threads to run. If this is
346 NULL, this function will read the first
347 argument and interpret it as the number
349 \param[out] nthreads the number of threads
351 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
352 int tMPI_Get_N(int *argc, char ***argv, const char *optname, int *nthreads);
356 /** Waits for all other threads to finish and cleans up
358 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
359 int tMPI_Finalize(void);
362 /** Just kills all threads.
364 Not really neccesary because exit() would do that for us anyway.
366 \param[in] comm Comm to kill threads for
367 \param[in] errorcode Error code to exit with
369 \return Never returns. */
370 int tMPI_Abort(tMPI_Comm comm, int errorcode);
372 /** whether tMPI_Init, but not yet tMPI_Finalize, has been run
374 \param[out] flag Set to TRUE if tMPI_Init() has been called,
377 \return always returns TMPI_SUCCESS. */
378 int tMPI_Initialized(int *flag);
380 /** Determine whether tMPI_Finalize has been run.
382 \param[out] flag Set to TRUE if tMPI_Finalize() has been
383 called, FALSE if not.
385 \return always returns TMPI_SUCCESS. */
386 int tMPI_Finalized(int *flag);
397 /*! \name Error handling functions
399 /** Create an error handler object from a function.
401 \param[in] function The function to make an error handler of.
402 \param[out] errhandler The error handler.
404 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
405 int tMPI_Create_errhandler(tMPI_Errhandler_fn *function,
406 tMPI_Errhandler *errhandler);
409 /** Free the error handler object.
411 \param[in] errhandler The error handler.
412 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
413 int tMPI_Errhandler_free(tMPI_Errhandler *errhandler);
415 /** Set the error handler.
417 \param[in] comm the communicator to set the error handler for.
418 \param[in] errhandler the error handler.
420 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
422 int tMPI_Comm_set_errhandler(tMPI_Comm comm, tMPI_Errhandler errhandler);
423 /** get the error handler.
425 Gets the error handler associated with a comm
427 \param[in] comm the communicator to get the error handler for.
428 \param[out] errhandler the error handler.
430 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
432 int tMPI_Comm_get_errhandler(tMPI_Comm comm, tMPI_Errhandler *errhandler);
434 /** get the error string associated with an error code.
436 The length of the error string will never exceed TMPI_MAX_ERROR_STRING.
438 \param[in] errorcode The error code.
439 \param[out] string The pre-allocated char pointer to output to.
440 \param[out] resultlen The length of the error string. Will
441 never be longer than TMPI_MAX_ERROR_STRING.
443 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
444 int tMPI_Error_string(int errorcode, char *string, size_t *resultlen);
454 /*! \name Environment query functions
456 /** returns string with thread number.
458 \param[out] name Pre-allocated string to output name to (will not
459 be longer than TMPI_MAX_PROCESSOR_NAME).
460 \param[out] resultlen The length of the output. Note that this is an
461 int instead of a size_t because the MPI standard
462 for some reason defines all sizes as int
464 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
465 int tMPI_Get_processor_name(char *name, int *resultlen);
467 /** get a time value as a double, in seconds.
471 double tMPI_Wtime(void);
472 /** get the resolution of tMPI_Wtime as a double, in seconds
474 \return time resolution. */
475 double tMPI_Wtick(void);
478 #define tMPI_This_threadnr() (int)(tMPI_Get_current() - threads)
480 /** Get the thread number of this thread.
481 Mostly for debugging.
483 \return the global thread number. */
484 int tMPI_This_Threadnr(void);
497 /*! \name tMPI_Group functions
499 /** Get the size (number of members) of a group.
501 \param[in] group The group.
502 \param[out] size Size.
503 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
504 int tMPI_Group_size(tMPI_Group group, int *size);
506 /** Get the rank of a thread in a group
508 \param[in] group The group.
509 \param[out] rank Variable for the rank, or TMPI_UNDEFINED
511 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
512 int tMPI_Group_rank(tMPI_Group group, int *rank);
514 /** Create a new group as a the collection of threads with given ranks.
516 \param[in] group The group from which the ranks are taken.
517 \param[in] n The number of new group members.
518 \param[in] ranks The ranks of the threads to add to the new group.
519 \param[out] newgroup The new group.
521 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
522 int tMPI_Group_incl(tMPI_Group group, int n, int *ranks, tMPI_Group *newgroup);
524 /** Get a pointer to the group in the comm.
526 \param[in] comm The comm from which to take the group.
527 \param[out] group The comm's group.
529 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
530 int tMPI_Comm_group(tMPI_Comm comm, tMPI_Group *group);
532 /** De-allocate a group
534 \param[in] group The group to de-allocate.
535 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
536 int tMPI_Group_free(tMPI_Group *group);
545 /*! \name tMPI_Comm functions
547 /** Get the comm size (nr. of threads).
549 \param[in] comm The comm to query.
550 \param[out] size The comm size.
551 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
552 int tMPI_Comm_size(tMPI_Comm comm, int *size);
554 /** get the rank in comm of the current process
556 \param[in] comm The comm to query.
557 \param[out] rank Thread rank in comm.
558 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
559 int tMPI_Comm_rank(tMPI_Comm comm, int *rank);
561 /** Compare two comms. Returns TMPI_IDENT if the two comms point to
562 the same underlying comm structure, TMPI_CONGRUENT if all
563 members appear in the both comms in the same order, TMPI_SIMILAR
564 if both comms have the smae members but not in the same order, or
565 TMPI_UNEQUAL if the comms have different members.
567 \param[in] comm1 The first comm to compare.
568 \param[in] comm2 The second comm to compare.
569 \param[out] result The output result, one of the values
571 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
572 int tMPI_Comm_compare(tMPI_Comm comm1, tMPI_Comm comm2, int *result);
575 /** De-allocate a comm
579 \param[in] comm The comm to free.
580 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
581 int tMPI_Comm_free(tMPI_Comm *comm);
583 /** Create a comm based on group membership.
585 Collective function that creates a new comm containing only proceses
586 that are members of the given group.
588 \param[in] comm The originating comm.
589 \param[in] group The group of threads to create a comm from.
590 \param[out] newcomm The new comm.
592 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
593 int tMPI_Comm_create(tMPI_Comm comm, tMPI_Group group, tMPI_Comm *newcomm);
595 /** Split up a group into same-colored sub-groups ordered by key.
597 This is the main comm creation function: it's a collective call that takes
598 a color and a key from each process, and arranges all threads that
599 call tMPI_Split() withe the same color together into a comm.
601 The rank in the new group will be based on the value given in key.
603 Passing TMPI_UNDEFINED as a color will result in the thread not being
604 part of any group, and getting TMPI_COMM_NULL back in newcomm.
606 \param[in] comm The originating comm.
607 \param[in] color This thread's color (determines which comm it will
608 be in). Giving TMPI_UNDEFINED will result in
609 this thread not being in any group.
610 \param[in] key This thread's key (determines rank).
611 \param[out] newcomm The new comm.
612 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
613 int tMPI_Comm_split(tMPI_Comm comm, int color, int key, tMPI_Comm *newcomm);
615 /** Make a duplicate of a comm.
619 \param[in] comm The originating comm.
620 \param[in] newcomm The new comm.
621 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
622 int tMPI_Comm_dup(tMPI_Comm comm, tMPI_Comm *newcomm);
632 /*! \name Topology functions
634 /* topology functions */
635 /** Check what type of topology the comm has.
637 \param[in] comm The comm to query
638 \param[out] status The type of topology.
640 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
641 int tMPI_Topo_test(tMPI_Comm comm, int *status);
643 /** Get the dimensionality of a comm with a topology.
645 \param[in] comm The comm to query.
646 \param[out] ndims The number of dimensions.
648 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
650 int tMPI_Cartdim_get(tMPI_Comm comm, int *ndims);
651 /** Get the size and pbc a of a comm with a Cartesian topology has.
653 \param[in] comm The comm to query.
654 \param[in] maxdims The maximum number of dimensions in the periods
655 and coords parameter.
656 \param[out] dims The number of dimensions.
657 \param[out] periods The periodicity in each dimension.
658 \param[out] coords The number of coordinates in each dimension.
660 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
662 int tMPI_Cart_get(tMPI_Comm comm, int maxdims, int *dims, int *periods,
666 /** Get rank that a specific set of process coordinates has in
667 a Cartesian topology.
669 \param[in] comm The comm to query.
670 \param[in] coords The coordinates in each dimension.
671 \param[out] rank The rank associated with the coordinates.
673 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
674 int tMPI_Cart_rank(tMPI_Comm comm, int *coords, int *rank);
676 /** Get coordinates of a process rank in a Cartesian topology.
678 \param[in] comm The comm to query.
679 \param[in] rank The rank associated with the coordinates.
680 \param[in] maxdims The maximum number of dimensions in the coords
682 \param[out] coords The coordinates in each dimension.
684 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
685 int tMPI_Cart_coords(tMPI_Comm comm, int rank, int maxdims, int *coords);
687 /** Get optimal rank this process would have in a Cartesian topology.
689 \param[in] comm The comm to query.
690 \param[in] ndims The number of dimensions.
691 \param[in] dims The size in each dimension.
692 \param[in] periods The periodicity in each dimension.
694 \param[out] newrank The rank the thread would have given the topology.
696 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
697 int tMPI_Cart_map(tMPI_Comm comm, int ndims, int *dims, int *periods,
700 /** Create a comm with a Cartesian topology.
702 \param[in] comm_old The originating comm.
703 \param[in] ndims The number of dimensions.
704 \param[in] dims The size in each dimension.
705 \param[in] periods The periodicity in each dimension.
706 \param[in] reorder Whether to allow reordering of the threads
707 according to tMPI_Cart_map().
708 \param[out] comm_cart The new comm with Cartesian topology.
710 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
711 int tMPI_Cart_create(tMPI_Comm comm_old, int ndims, int *dims, int *periods,
712 int reorder, tMPI_Comm *comm_cart);
714 /** Create a comms that are sub-spaces of the Cartesian topology communicator.
715 Works like a MPI_Comm_split() for the Cartesian dimensions specified
716 as false in remain_dims.
718 \param[in] comm The originating comm with Cartesian topology.
719 \param[in] remain_dims An Boolean array that decides whether a specific
720 dimensionality should remain in newcomm (if true),
721 or should be split up (if false).
722 \param[out] newcomm The new split communicator
724 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
725 int tMPI_Cart_sub(tMPI_Comm comm, int *remain_dims, tMPI_Comm *newcomm);
736 /*! \name Data type manipulation functions
738 /** Create a contiguous data type (the only type possible right now).
740 Creates a datatype that is a vector of oldtype.
742 \param[in] count The number of oldtype types in the new type.
743 \param[in] oldtype The old data type.
744 \param[out] newtype The new data type (still needs to be committed).
745 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
746 int tMPI_Type_contiguous(int count, tMPI_Datatype oldtype,
747 tMPI_Datatype *newtype);
750 /** Make a data type ready for use.
752 \param[in,out] datatype The new datatype.
753 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
754 int tMPI_Type_commit(tMPI_Datatype *datatype);
764 /*! \name Point-to-point communication functions
767 /* blocking transfers. The actual transfer (copy) is done on the receiving end
768 (so that the receiver's cache already contains the data that it presumably
770 /** Send message; blocks until buf is reusable.
772 \param[in] buf The buffer with data to send.
773 \param[in] count The number of items to send.
774 \param[in] datatype The data type of the items in buf.
775 \param[in] dest The rank of the destination thread.
776 \param[in] tag The message tag.
777 \param[in] comm The shared communicator.
778 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
779 int tMPI_Send(void* buf, int count, tMPI_Datatype datatype, int dest,
780 int tag, tMPI_Comm comm);
782 /** Receive message; blocks until buf is filled.
784 \param[out] buf The buffer for data to receive.
785 \param[in] count The maximum number of items to receive.
786 \param[in] datatype The data type of the items in buf.
787 \param[in] source The rank of the source thread (or TMPI_ANY_SOURCE).
788 \param[in] tag The message tag (or TMPI_ANY_TAG).
789 \param[in] comm The shared communicator.
790 \param[out] status The message status.
791 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
792 int tMPI_Recv(void* buf, int count, tMPI_Datatype datatype, int source,
793 int tag, tMPI_Comm comm, tMPI_Status *status);
795 /** Send & receive message at the same time.
797 Blocks until recvbuf is filled, and sendbuf is ready for reuse.
799 \param[in] sendbuf The buffer with data to send.
800 \param[in] sendcount The number of items to send.
801 \param[in] sendtype The data type of the items in send buf.
802 \param[in] dest The rank of the destination thread.
803 \param[in] sendtag The send message tag.
804 \param[out] recvbuf The buffer for data to receive.
805 \param[in] recvcount The maximum number of items to receive.
806 \param[in] recvtype The data type of the items in recvbuf.
807 \param[in] source The rank of the source thread (or TMPI_ANY_SOURCE).
808 \param[in] recvtag The recveive message tag (or TMPI_ANY_TAG).
809 \param[in] comm The shared communicator.
810 \param[out] status The received message status.
811 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
812 int tMPI_Sendrecv(void *sendbuf, int sendcount, tMPI_Datatype sendtype,
813 int dest, int sendtag, void *recvbuf, int recvcount,
814 tMPI_Datatype recvtype, int source, int recvtag,
815 tMPI_Comm comm, tMPI_Status *status);
817 /* async send/recv. The actual transfer is done on the receiving
818 end, during tMPI_Wait, tMPI_Waitall or tMPI_Test. For tMPI_Waitall,
819 the incoming messages are processed in the order they come in. */
821 /** Initiate sending a message, non-blocking.
823 This makes the buffer available to be received. The contents of buf
824 should not be touched before the transmission is finished with
825 tMPI_Wait(), tMPI_Test() or tMPI_Waitall().
828 \param[in] buf The buffer with data to send.
829 \param[in] count The number of items to send.
830 \param[in] datatype The data type of the items in buf.
831 \param[in] dest The rank of the destination thread.
832 \param[in] tag The message tag.
833 \param[in] comm The shared communicator.
834 \param[out] request The request object that can be used in tMPI_Wait(),
836 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
837 int tMPI_Isend(void* buf, int count, tMPI_Datatype datatype, int dest,
838 int tag, tMPI_Comm comm, tMPI_Request *request);
840 /** Initiate receiving a message.
842 This makes the buffer available to be filled with data. The contents of
843 buf should not be relied on before the transmission is finished with
844 tMPI_Wait(), tMPI_Test() or tMPI_Waitall().
846 \param[out] buf The buffer for data to receive.
847 \param[in] count The maximum number of items to receive.
848 \param[in] datatype The data type of the items in buf.
849 \param[in] source The rank of the source thread (or TMPI_ANY_SOURCE).
850 \param[in] tag The message tag (or TMPI_ANY_TAG).
851 \param[in] comm The shared communicator.
852 \param[out] request The request object that can be used in tMPI_Wait(),
854 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
855 int tMPI_Irecv(void* buf, int count, tMPI_Datatype datatype, int source,
856 int tag, tMPI_Comm comm, tMPI_Request *request);
861 /** Test whether a message is transferred.
863 \param[in,out] request The request obtained wit tMPI_Isend()/tMPI_Irecv().
864 \param[out] flag A flag set to TRUE(1) if the request is finished,
866 \param[out] status Message status (can be set to TMPI_STATUS_IGNORE).
868 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
869 int tMPI_Test(tMPI_Request *request, int *flag, tMPI_Status *status);
871 /** Wait until a message is transferred.
873 \param[in,out] request The request obtained wit tMPI_Isend()/tMPI_Irecv().
874 \param[out] status Message status.
876 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
877 int tMPI_Wait(tMPI_Request *request, tMPI_Status *status);
882 /** Wait until several messages are transferred.
884 \param[in] count The number of requests
885 \param[in,out] array_of_requests List of count requests obtained with
886 tMPI_Isend()/tMPI_Irecv().
887 \param[out] array_of_statuses List of count message statuses (can
888 be set to TMPI_STATUSES_IGNORE).
890 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
891 int tMPI_Waitall(int count, tMPI_Request *array_of_requests,
892 tMPI_Status *array_of_statuses);
894 /** Test whether several messages are transferred.
896 \param[in] count The number of requests
897 \param[in,out] array_of_requests List of count requests obtained with
898 tMPI_Isend()/tMPI_Irecv().
899 \param[out] flag Whether all requests have completed.
900 \param[out] array_of_statuses List of count message statuses (can
901 be set to TMPI_STATUSES_IGNORE).
903 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
904 int tMPI_Testall(int count, tMPI_Request *array_of_requests, int *flag,
905 tMPI_Status *array_of_statuses);
907 /** Wait until one of several messages is transferred.
909 \param[in] count The number of requests
910 \param[in,out] array_of_requests List of count requests obtained with
911 tMPI_Isend()/tMPI_Irecv().
912 \param[out] index Index of the request that has
914 \param[out] status Pointer to tMPI_Status object
915 associated with completed request.
917 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
918 int tMPI_Waitany(int count, tMPI_Request *array_of_requests,
919 int *index, tMPI_Status *status);
921 /** Test whether one of several messages is transferred.
923 \param[in] count The number of requests
924 \param[in,out] array_of_requests List of count requests obtained with
925 tMPI_Isend()/tMPI_Irecv().
926 \param[out] index Index of the request that has
928 \param[out] flag Whether any request has completed.
929 \param[out] status Pointer to tMPI_Status object
930 associated with completed request.
932 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
933 int tMPI_Testany(int count, tMPI_Request *array_of_requests,
934 int *index, int *flag, tMPI_Status *status);
936 /** Wait until some of several messages are transferred. Waits until at least
937 one message is transferred.
939 \param[in] count The number of requests
940 \param[in,out] array_of_requests List of count requests obtained with
941 tMPI_Isend()/tMPI_Irecv().
942 \param[out] outcount Number of completed requests
943 \param[out] array_of_indices Array of ints that gets filled with
944 the indices of the completed requests.
945 \param[out] array_of_statuses List of count message statuses (can
946 be set to TMPI_STATUSES_IGNORE).
948 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
949 int tMPI_Waitsome(int incount, tMPI_Request *array_of_requests,
950 int *outcount, int *array_of_indices,
951 tMPI_Status *array_of_statuses);
953 /** Test whether some of several messages are transferred.
955 \param[in] count The number of requests
956 \param[in,out] array_of_requests List of count requests obtained with
957 tMPI_Isend()/tMPI_Irecv().
958 \param[out] outcount Number of completed requests
959 \param[out] array_of_indices Array of ints that gets filled with
960 the indices of the completed requests.
961 \param[out] array_of_statuses List of count message statuses (can
962 be set to TMPI_STATUSES_IGNORE).
964 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
965 int tMPI_Testsome(int incount, tMPI_Request *array_of_requests,
966 int *outcount, int *array_of_indices,
967 tMPI_Status *array_of_statuses);
974 /** get the number of actually transferred items from a receive
977 \param[in] status The status.
978 \param[in] datatype The data type which was received.
979 \param[out] count The number of items actually received.
981 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
982 int tMPI_Get_count(tMPI_Status *status, tMPI_Datatype datatype, int *count);
992 /*! \name Synchronization functions
994 /** Block until all threads in the comm call this function.
996 \param[in] comm The comm object.
998 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
999 int tMPI_Barrier(tMPI_Comm comm);
1008 /*! \name Multicast communication functions
1010 /** Broadcast from one thread to all others in comm.
1012 Collective function; data is transferred from root's buffer to all others'
1015 \param[in,out] buffer The buffer to send from (root)/receive from
1017 \param[in] count The number of items to send/receive.
1018 \param[in] datatype The type of the items to send/receive.
1019 \param[in] root The rank of the sending thread.
1020 \param[in] comm The communicator.
1022 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
1023 int tMPI_Bcast(void* buffer, int count, tMPI_Datatype datatype, int root,
1026 /** Gather data from all threads in comm to root.
1028 Collective function; assumes that all data is received in blocks of
1031 \param[in] sendbuf The send buffer for all threads (root may
1032 specify TMPI_IN_PLACE, in which case it
1033 transfers nothing to itself).
1034 \param[in] sendcount The number of items to send for all threads.
1035 \param[in] sendtype The type of the items to send.
1036 \param[out] recvbuf The receiving buffer (for root thread).
1037 \param[in] recvcount The number of items to receive (for root).
1038 \param[in] recvtype The type of the items to receive (for root).
1039 \param[in] root The rank of root.
1040 \param[in] comm The communicator.
1042 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
1043 int tMPI_Gather(void* sendbuf, int sendcount, tMPI_Datatype sendtype,
1044 void* recvbuf, int recvcount, tMPI_Datatype recvtype, int root,
1048 /** Gather irregularly laid out data from all processes in comm to root.
1050 Collective function.
1052 \param[in] sendbuf The send buffer for all threads (root may
1053 specify TMPI_IN_PLACE, in which case it
1054 transfers nothing to itself).
1055 \param[in] sendcount The number of items to send for all threads.
1056 \param[in] sendtype The type of the items to send.
1057 \param[out] recvbuf The receiving buffer (for root thread).
1058 \param[in] recvcounts The list of number of items to receive (for
1060 \param[in] displs The list of displacements in recvbuf to
1061 receive data in (for root).
1062 \param[in] recvtype The type of the items to receive (for root).
1063 \param[in] root The rank of root.
1064 \param[in] comm The communicator.
1066 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
1067 int tMPI_Gatherv(void* sendbuf, int sendcount, tMPI_Datatype sendtype,
1068 void* recvbuf, int *recvcounts, int *displs,
1069 tMPI_Datatype recvtype, int root, tMPI_Comm comm);
1072 /** Spread parts of sendbuf to all processes in comm from root.
1074 Collective function.
1076 \param[in] sendbuf The send buffer for root.
1077 \param[in] sendcount The number of items for root to send to each
1079 \param[in] sendtype The type of the items root sends.
1080 \param[out] recvbuf The receiving buffer for all receiving threads
1081 (root may specify TMPI_IN_PLACE, in which case
1082 it transmits nothing to itself).
1083 \param[in] recvcount The number of items recvbuf can receive.
1084 \param[in] recvtype The type of items to receive.
1085 \param[in] root The rank of root.
1086 \param[in] comm The communicator.
1088 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
1089 int tMPI_Scatter(void* sendbuf, int sendcount, tMPI_Datatype sendtype,
1090 void* recvbuf, int recvcount, tMPI_Datatype recvtype, int root,
1093 /** Spread irregularly laid out parts of sendbuf to all processes
1096 Collective function.
1098 \param[in] sendbuf The send buffer for root.
1099 \param[in] sendcounts List of the number of items for root to send
1101 \param[in] displs List of displacements in sendbuf from which
1102 to start transmission to each thread.
1103 \param[in] sendtype The type of the items root sends.
1104 \param[out] recvbuf The receiving buffer for all receiving threads
1105 (root may specify TMPI_IN_PLACE, in which case
1106 it transmits nothing to itself).
1107 \param[in] recvcount The number of items recvbuf can receive.
1108 \param[in] recvtype The type of items to receive.
1109 \param[in] root The rank of root.
1110 \param[in] comm The communicator.
1112 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
1113 int tMPI_Scatterv(void* sendbuf, int *sendcounts, int *displs,
1114 tMPI_Datatype sendtype, void* recvbuf, int recvcount,
1115 tMPI_Datatype recvtype, int root, tMPI_Comm comm);
1118 /** Spread out parts of sendbuf to all processes from all processes in
1121 Collective function.
1123 \param[in] sendbuf The send buffer.
1124 \param[in] sendcount The number of items for to send to each thread.
1125 \param[in] sendtype The type of the items to send.
1126 \param[out] recvbuf The receive buffer for all threads.
1127 \param[in] recvcount The number of items recvbuf can receive per
1129 \param[in] recvtype The type of items to receive.
1130 \param[in] comm The communicator.
1132 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
1133 int tMPI_Alltoall(void* sendbuf, int sendcount, tMPI_Datatype sendtype,
1134 void* recvbuf, int recvcount, tMPI_Datatype recvtype,
1138 /** Spread out irregularly laid out parts of sendbuf to all
1139 processes from all processes in comm.
1141 Collective function.
1143 \param[in] sendbuf The send buffer.
1144 \param[in] sendcounts List of the number of items for to send to
1146 \param[in] sdispls List of the displacements in sendbuf of items
1147 to send to each thread.
1148 \param[in] sendtype The type of the items to send.
1149 \param[out] recvbuf The receive buffer for all threads.
1150 \param[in] recvcounts List of the number of items recvbuf can
1151 receive from each thread.
1152 \param[in] rdispls List of the displacements in recvbuf of items
1153 to receive from each thread.
1154 \param[in] recvtype The type of items to receive.
1155 \param[in] comm The communicator.
1157 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
1158 int tMPI_Alltoallv(void* sendbuf, int *sendcounts, int *sdispls,
1159 tMPI_Datatype sendtype, void* recvbuf, int *recvcounts,
1160 int *rdispls, tMPI_Datatype recvtype, tMPI_Comm comm);
1172 /*! \name Reduce functions
1174 /** Do an operation between all locally held buffers on all items in the
1175 buffers, and send the results to root.
1177 Collective function.
1179 \param[in] sendbuf The operand parameters. Root may specify
1180 TMPI_IN_PLACE, in which case recvbuf will hold
1181 the operand parameters.
1182 \param[out] recvbuf The result buffer at root.
1183 \param[in] count The number of items to do operation on.
1184 \param[in] datatype The data type of the items.
1185 \param[in] op The operation to perform.
1186 \param[in] root The root thread (which is to receive the results).
1187 \param[in] comm The communicator.
1189 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
1190 int tMPI_Reduce(void* sendbuf, void* recvbuf, int count,
1191 tMPI_Datatype datatype, tMPI_Op op, int root, tMPI_Comm comm);
1195 /** Do an operation between all locally held buffers on all items in the
1196 buffers and broadcast the results.
1198 Collective function.
1201 \param[in] sendbuf The operand parameters. Any process may specify
1202 TMPI_IN_PLACE, in which case recvbuf will hold
1203 the operand parameters for that process.
1204 \param[out] recvbuf The result buffer.
1205 \param[in] count The number of items to do operation on.
1206 \param[in] datatype The data type of the items.
1207 \param[in] op The operation to perform.
1208 \param[in] comm The communicator.
1210 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
1211 int tMPI_Allreduce(void* sendbuf, void* recvbuf, int count,
1212 tMPI_Datatype datatype, tMPI_Op op, tMPI_Comm comm);
1214 /** Do an tMPI_Reduce, but with the following assumption:
1215 recvbuf points to a valid buffer in all calling threads, or
1216 sendbuf has the value TMPI_IN_PLACE (in which case the values of
1217 sendbuf may be changed in that thread).
1219 This avoids unnecesary memory allocations associated with the normal
1222 Collective function.
1224 \param[in] sendbuf The operand parameters (or TMPI_IN_PLACE,
1225 in which case the operand parameters will
1227 \param[in,out] recvbuf The result buffer.
1228 \param[in] count The number of items to do operation on.
1229 \param[in] datatype The data type of the items.
1230 \param[in] op The operation to perform.
1231 \param[in] root The root thread (which is to receive
1233 \param[in] comm The communicator.
1235 \return TMPI_SUCCESS on success, TMPI_FAILURE on failure. */
1236 int tMPI_Reduce_fast(void* sendbuf, void* recvbuf, int count,
1237 tMPI_Datatype datatype, tMPI_Op op, int root,
1244 } /* closing extern "C" */
1247 #endif /* _TMPI_H_ */