1 /* begin_generated_IBM_copyright_prolog                             */
2 /*                                                                  */
3 /* This is an automatically generated copyright prolog.             */
4 /* After initializing,  DO NOT MODIFY OR MOVE                       */
5 /*  --------------------------------------------------------------- */
6 /* Licensed Materials - Property of IBM                             */
7 /* Blue Gene/Q 5765-PER 5765-PRP                                    */
8 /*                                                                  */
9 /* (C) Copyright IBM Corp. 2011, 2012 All Rights Reserved           */
10 /* US Government Users Restricted Rights -                          */
11 /* Use, duplication, or disclosure restricted                       */
12 /* by GSA ADP Schedule Contract with IBM Corp.                      */
13 /*                                                                  */
14 /*  --------------------------------------------------------------- */
15 /*                                                                  */
16 /* end_generated_IBM_copyright_prolog                               */
17 /*  (C)Copyright IBM Corp.  2007, 2011  */
18 /**
19  * \file src/mpid_request.c
20  * \brief Accessors and actors for MPID Requests
21  */
22 #include <mpidimpl.h>
23 
24 #ifndef MPID_REQUEST_PREALLOC
25 #if (MPIU_THREAD_GRANULARITY == MPIU_THREAD_GRANULARITY_GLOBAL)
26 #define  MPID_REQUEST_PREALLOC 16
27 #elif (MPIU_HANDLE_ALLOCATION_METHOD == MPIU_HANDLE_ALLOCATION_THREAD_LOCAL)
28 #define  MPID_REQUEST_PREALLOC 512  //Have direct more reqyests for all threads
29 #endif
30 #endif
31 
32 /**
33  * \defgroup MPID_REQUEST MPID Request object management
34  *
35  * Accessors and actors for MPID Requests
36  */
37 
38 
39 /* these are referenced by src/mpi/pt2pt/wait.c in PMPI_Wait! */
40 MPID_Request MPID_Request_direct[MPID_REQUEST_PREALLOC] __attribute__((__aligned__(64)));
41 MPIU_Object_alloc_t MPID_Request_mem =
42   {
43     0, 0, 0, 0, MPID_REQUEST, sizeof(MPID_Request),
44     MPID_Request_direct,
45     MPID_REQUEST_PREALLOC
46   };
47 
48 
49 #if (MPIU_HANDLE_ALLOCATION_METHOD == MPIU_HANDLE_ALLOCATION_THREAD_LOCAL) && defined(__BGQ__)
MPIDI_Request_allocate_pool()50 void MPIDI_Request_allocate_pool()
51 {
52   int i;
53   MPID_Request *prev, *cur;
54   /* batch allocate a linked list of requests */
55   MPIU_THREAD_CS_ENTER(HANDLEALLOC,);
56   prev = MPIU_Handle_obj_alloc_unsafe(&MPID_Request_mem);
57   MPID_assert(prev != NULL);
58   prev->mpid.next = NULL;
59   for (i = 1; i < MPID_REQUEST_TLS_MAX; ++i) {
60     cur = MPIU_Handle_obj_alloc_unsafe(&MPID_Request_mem);
61     MPID_assert(cur != NULL);
62     cur->mpid.next = prev;
63     prev = cur;
64   }
65   MPIU_THREAD_CS_EXIT(HANDLEALLOC,);
66   MPIDI_Process.request_handles[MPIDI_THREAD_ID()].head = cur;
67   MPIDI_Process.request_handles[MPIDI_THREAD_ID()].count += MPID_REQUEST_TLS_MAX;
68 }
69 #endif
70 
71 
72 void
MPIDI_Request_uncomplete(MPID_Request * req)73 MPIDI_Request_uncomplete(MPID_Request *req)
74 {
75   int count;
76   MPIU_Object_add_ref(req);
77   MPID_cc_incr(req->cc_ptr, &count);
78 }
79 
80 
81 void
MPID_Request_set_completed(MPID_Request * req)82 MPID_Request_set_completed(MPID_Request *req)
83 {
84   MPID_cc_set(&req->cc, 0);
85   MPIDI_Progress_signal();
86 }
87