00001
00002
00003
00004
00005
00006
00007
00008 #include "adio.h"
00009 #include "adio_extern.h"
00010
00011 ADIOI_Async_node *ADIOI_Malloc_async_node(void)
00012 {
00013
00014
00015
00016
00017
00018
00019 #define NUM 100
00020
00021 ADIOI_Async_node *curr, *ptr;
00022 int i;
00023
00024 if (!ADIOI_Async_avail_head) {
00025 ADIOI_Async_avail_head = (ADIOI_Async_node *)
00026 ADIOI_Malloc(NUM*sizeof(ADIOI_Async_node));
00027 curr = ADIOI_Async_avail_head;
00028 for (i=1; i<NUM; i++) {
00029 curr->next = ADIOI_Async_avail_head+i;
00030 curr = curr->next;
00031 }
00032 curr->next = NULL;
00033 ADIOI_Async_avail_tail = curr;
00034
00035
00036 if (!ADIOI_Malloc_async_tail) {
00037 ADIOI_Malloc_async_tail = (ADIOI_Malloc_async *)
00038 ADIOI_Malloc(sizeof(ADIOI_Malloc_async));
00039 ADIOI_Malloc_async_head = ADIOI_Malloc_async_tail;
00040 ADIOI_Malloc_async_head->ptr = ADIOI_Async_avail_head;
00041 ADIOI_Malloc_async_head->next = NULL;
00042 }
00043 else {
00044 ADIOI_Malloc_async_tail->next = (ADIOI_Malloc_async *)
00045 ADIOI_Malloc(sizeof(ADIOI_Malloc_async));
00046 ADIOI_Malloc_async_tail = ADIOI_Malloc_async_tail->next;
00047 ADIOI_Malloc_async_tail->ptr = ADIOI_Async_avail_head;
00048 ADIOI_Malloc_async_tail->next = NULL;
00049 }
00050 }
00051
00052 ptr = ADIOI_Async_avail_head;
00053 ADIOI_Async_avail_head = ADIOI_Async_avail_head->next;
00054 if (!ADIOI_Async_avail_head) ADIOI_Async_avail_tail = NULL;
00055
00056 return ptr;
00057 }
00058
00059
00060 void ADIOI_Free_async_node(ADIOI_Async_node *node)
00061 {
00062
00063
00064 if (!ADIOI_Async_avail_tail)
00065 ADIOI_Async_avail_head = ADIOI_Async_avail_tail = node;
00066 else {
00067 ADIOI_Async_avail_tail->next = node;
00068 ADIOI_Async_avail_tail = node;
00069 }
00070 node->next = NULL;
00071 }
00072
00073
00074 void ADIOI_Add_req_to_list(ADIO_Request *request)
00075 {
00076
00077
00078 ADIOI_Async_node *curr;
00079
00080 if (!ADIOI_Async_list_head) {
00081 ADIOI_Async_list_head = ADIOI_Malloc_async_node();
00082 ADIOI_Async_list_head->request = request;
00083 ADIOI_Async_list_head->prev = ADIOI_Async_list_head->next = NULL;
00084 ADIOI_Async_list_tail = ADIOI_Async_list_head;
00085 (*request)->ptr_in_async_list = ADIOI_Async_list_head;
00086 }
00087 else {
00088 curr = ADIOI_Async_list_tail;
00089 curr->next = ADIOI_Malloc_async_node();
00090 ADIOI_Async_list_tail = curr->next;
00091 ADIOI_Async_list_tail->request = request;
00092 ADIOI_Async_list_tail->prev = curr;
00093 ADIOI_Async_list_tail->next = NULL;
00094 (*request)->ptr_in_async_list = ADIOI_Async_list_tail;
00095 }
00096 }
00097
00098
00099
00100
00101 void ADIOI_Complete_async(int *error_code)
00102 {
00103
00104
00105
00106 ADIO_Status status;
00107 ADIO_Request *request;
00108 ADIOI_Async_node *tmp;
00109 static char myname[] = "ADIOI_Complete_async";
00110
00111 *error_code = MPI_SUCCESS;
00112
00113 while (ADIOI_Async_list_head) {
00114 request = ADIOI_Async_list_head->request;
00115 (*request)->queued = -1;
00116
00117
00118
00119 switch ((*request)->optype) {
00120 case ADIOI_READ:
00121
00122
00123 ADIO_ReadComplete(request, &status, error_code);
00124 break;
00125 case ADIOI_WRITE:
00126
00127
00128 ADIO_WriteComplete(request, &status, error_code);
00129 break;
00130 default:
00131
00132 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00133 MPIR_ERR_RECOVERABLE,
00134 myname, __LINE__,
00135 MPI_ERR_INTERN,
00136 "Unknown request optype", 0);
00137 return;
00138
00139 }
00140 (*request)->queued = 0;
00141
00142
00143 tmp = ADIOI_Async_list_head;
00144 ADIOI_Async_list_head = ADIOI_Async_list_head->next;
00145 ADIOI_Free_async_node(tmp);
00146 }
00147 ADIOI_Async_list_tail = NULL;
00148 }
00149
00150
00151 void ADIOI_Del_req_from_list(ADIO_Request *request)
00152 {
00153
00154
00155
00156
00157 ADIOI_Async_node *curr, *prev, *next;
00158
00159 curr = (*request)->ptr_in_async_list;
00160 prev = curr->prev;
00161
00162 if (prev) prev->next = curr->next;
00163 else ADIOI_Async_list_head = curr->next;
00164
00165 next = curr->next;
00166 if (next) next->prev = prev;
00167 else ADIOI_Async_list_tail = prev;
00168
00169 ADIOI_Free_async_node(curr);
00170 }