/* ============================================================================= * TMheap_insert * -- Returns false on failure * ============================================================================= */ bool TMheap_insert (TM_ARGDECL heap_t* heapPtr, void* dataPtr) { long size = (long)TM_SHARED_READ_L(heapPtr->size); long capacity = (long)TM_SHARED_READ_L(heapPtr->capacity); if ((size + 1) >= capacity) { long newCapacity = capacity * 2; void** newElements = (void**)TM_MALLOC(newCapacity * sizeof(void*)); if (newElements == NULL) { return false; } TM_SHARED_WRITE_L(heapPtr->capacity, newCapacity); long i; void** elements = TM_SHARED_READ_P(heapPtr->elements); for (i = 0; i <= size; i++) { newElements[i] = (void*)TM_SHARED_READ_P(elements[i]); } TM_FREE(elements); TM_SHARED_WRITE_P(heapPtr->elements, newElements); } size++; TM_SHARED_WRITE_L(heapPtr->size, size); void** elements = (void**)TM_SHARED_READ_P(heapPtr->elements); TM_SHARED_WRITE_P(elements[size], dataPtr); TMsiftUp(TM_ARG heapPtr, size); return true; }
TM_SAFE bool_t TMheap_insert ( heap_t* heapPtr, void* dataPtr) { long size = (long)TM_SHARED_READ(heapPtr->size); long capacity = (long)TM_SHARED_READ(heapPtr->capacity); if ((size + 1) >= capacity) { long newCapacity = capacity * 2; void** newElements = (void**)TM_MALLOC(newCapacity * sizeof(void*)); if (newElements == NULL) { return FALSE; } TM_SHARED_WRITE(heapPtr->capacity, newCapacity); long i; void** elements = (void **)TM_SHARED_READ_P(heapPtr->elements); for (i = 0; i <= size; i++) { newElements[i] = (void*)TM_SHARED_READ_P(elements[i]); } free(heapPtr->elements); TM_SHARED_WRITE_P(heapPtr->elements, newElements); } size++; TM_SHARED_WRITE(heapPtr->size, size); void** elements = (void**)TM_SHARED_READ_P(heapPtr->elements); TM_SHARED_WRITE_P(elements[size], dataPtr); siftUp(heapPtr, size); return TRUE; }
/* ============================================================================= * TMhashtable_alloc * -- Returns NULL on failure * -- Negative values for resizeRatio or growthFactor select default values * ============================================================================= */ hashtable_t* TMhashtable_alloc (TM_ARGDECL long initNumBucket, ulong_t (*hash)(const void*), long (*comparePairs)(const pair_t*, const pair_t*), long resizeRatio, long growthFactor) { hashtable_t* hashtablePtr; hashtablePtr = (hashtable_t*)TM_MALLOC(sizeof(hashtable_t)); if (hashtablePtr == NULL) { return NULL; } hashtablePtr->buckets = TMallocBuckets(TM_ARG initNumBucket, comparePairs); if (hashtablePtr->buckets == NULL) { TM_FREE(hashtablePtr); return NULL; } hashtablePtr->numBucket = initNumBucket; #ifdef HASHTABLE_SIZE_FIELD hashtablePtr->size = 0; #endif hashtablePtr->hash = hash; hashtablePtr->comparePairs = comparePairs; hashtablePtr->resizeRatio = ((resizeRatio < 0) ? HASHTABLE_DEFAULT_RESIZE_RATIO : resizeRatio); hashtablePtr->growthFactor = ((growthFactor < 0) ? HASHTABLE_DEFAULT_GROWTH_FACTOR : growthFactor); return hashtablePtr; }
heap_t* TMheap_alloc (TM_ARGDECL long initCapacity, comparator_t* compare) { heap_t* heapPtr; heapPtr = (heap_t*)TM_MALLOC(sizeof(heap_t)); if (heapPtr) { long capacity = ((initCapacity > 0) ? (initCapacity) : (1)); heapPtr->elements = (void**)TM_MALLOC(capacity * sizeof(void*)); assert(heapPtr->elements); heapPtr->size = 0; heapPtr->capacity = capacity; heapPtr->compare = compare; } return heapPtr; }
/* ============================================================================= * TMrbtree_alloc * ============================================================================= */ rbtree_t* TMrbtree_alloc (TM_ARGDECL comparator_t* compare) { rbtree_t* n = (rbtree_t* )TM_MALLOC(sizeof(*n)); if (n){ n->compare = ((compare == NULL) ? compare : &rbtree_comparekeysdefault); n->root = NULL; } return n; }
/* ============================================================================= * TMqueue_alloc * ============================================================================= */ queue_t* TMqueue_alloc (TM_ARGDECL long initCapacity) { queue_t* queuePtr = (queue_t*)TM_MALLOC(sizeof(queue_t)); if (queuePtr) { long capacity = ((initCapacity < 2) ? 2 : initCapacity); queuePtr->elements = (void**)TM_MALLOC(capacity * sizeof(void*)); if (queuePtr->elements == NULL) { free(queuePtr); return NULL; } queuePtr->pop = capacity - 1; queuePtr->push = 0; queuePtr->capacity = capacity; } return queuePtr; }
/* ============================================================================= * TMallocNode * -- Returns NULL on failure * ============================================================================= */ static TM_CALLABLE list_node_t* TMallocNode (TM_ARGDECL void* dataPtr) { list_node_t* nodePtr = (list_node_t*)TM_MALLOC(sizeof(list_node_t)); if (nodePtr == NULL) { return NULL; } nodePtr->dataPtr = dataPtr; nodePtr->nextPtr = NULL; return nodePtr; }
/* ============================================================================= * reservation_info_alloc * -- Returns NULL on failure * ============================================================================= */ reservation_info_t* reservation_info_alloc (TM_ARGDECL reservation_type_t type, long id, int price) { reservation_info_t* reservationInfoPtr; reservationInfoPtr = (reservation_info_t*)TM_MALLOC(sizeof(reservation_info_t)); if (reservationInfoPtr != NULL) { reservationInfoPtr->type = type; reservationInfoPtr->id = id; reservationInfoPtr->price = price; } return reservationInfoPtr; }
/* ============================================================================= * TMqueue_push * ============================================================================= */ bool_t TMqueue_push (TM_ARGDECL queue_t* queuePtr, void* dataPtr) { long pop = (long)TM_SHARED_READ(queuePtr->pop); long push = (long)TM_SHARED_READ(queuePtr->push); long capacity = (long)TM_SHARED_READ(queuePtr->capacity); assert(pop != push); /* Need to resize */ long newPush = (push + 1) % capacity; if (newPush == pop) { long newCapacity = capacity * QUEUE_GROWTH_FACTOR; void** newElements = (void**)TM_MALLOC(newCapacity * sizeof(void*)); if (newElements == NULL) { return FALSE; } long dst = 0; void** elements = (void**)TM_SHARED_READ_P(queuePtr->elements); if (pop < push) { long src; for (src = (pop + 1); src < push; src++, dst++) { newElements[dst] = (void*)TM_SHARED_READ_P(elements[src]); } } else { long src; for (src = (pop + 1); src < capacity; src++, dst++) { newElements[dst] = (void*)TM_SHARED_READ_P(elements[src]); } for (src = 0; src < push; src++, dst++) { newElements[dst] = (void*)TM_SHARED_READ_P(elements[src]); } } TM_FREE(elements); TM_SHARED_WRITE_P(queuePtr->elements, newElements); TM_SHARED_WRITE(queuePtr->pop, newCapacity - 1); TM_SHARED_WRITE(queuePtr->capacity, newCapacity); push = dst; newPush = push + 1; /* no need modulo */ } void** elements = (void**)TM_SHARED_READ_P(queuePtr->elements); TM_SHARED_WRITE_P(elements[push], dataPtr); TM_SHARED_WRITE(queuePtr->push, newPush); return TRUE; }
/* ============================================================================= * customer_alloc * ============================================================================= */ customer_t* customer_alloc (TM_ARGDECL long id) { customer_t* customerPtr; customerPtr = (customer_t*)TM_MALLOC(sizeof(customer_t)); assert(customerPtr != NULL); customerPtr->id = id; customerPtr->reservationInfoListPtr = TMLIST_ALLOC(&customer_comparereservationinfo); assert(customerPtr->reservationInfoListPtr != NULL); return customerPtr; }
/* ============================================================================= * reservation_alloc * -- Returns NULL on failure * ============================================================================= */ reservation_t* reservation_alloc (TM_ARGDECL long id, int numTotal, int price) { _reservation_t* _reservationPtr; _reservationPtr = (_reservation_t*)TM_MALLOC(sizeof(_reservation_t)); if (_reservationPtr != NULL) { _reservationPtr->id = id; _reservationPtr->numUsed = 0; _reservationPtr->numFree = numTotal; _reservationPtr->numTotal = numTotal; _reservationPtr->price = price; } return TM_RESERVATION_ALLOC(_reservationPtr); }
/* ============================================================================= * reservation_alloc * -- Returns NULL on failure * ============================================================================= */ reservation_t* reservation_stm::reservation_alloc (TM_ARGDECL long id, long numTotal, long price) { reservation_t* reservationPtr; reservationPtr = (reservation_t*)TM_MALLOC(sizeof(reservation_t)); if (reservationPtr != NULL) { reservationPtr->id = id; reservationPtr->numUsed = 0; reservationPtr->numFree = numTotal; reservationPtr->numTotal = numTotal; reservationPtr->price = price; CHECK_RESERVATION(reservationPtr); } return reservationPtr; }
region_t* TMregion_alloc (TM_ARGDECL_ALONE) { region_t* regionPtr; regionPtr = (region_t*)TM_MALLOC(sizeof(region_t)); if (regionPtr) { regionPtr->expandQueuePtr = TMQUEUE_ALLOC(-1); assert(regionPtr->expandQueuePtr); regionPtr->beforeListPtr = TMLIST_ALLOC(®ion_elementlistcompare); assert(regionPtr->beforeListPtr); regionPtr->borderListPtr = TMLIST_ALLOC(®ion_listcompareedge); assert(regionPtr->borderListPtr); regionPtr->badVectorPtr = PVECTOR_ALLOC(1); assert(regionPtr->badVectorPtr); } return regionPtr; }
/* ============================================================================= * list_alloc * -- If NULL passed for 'compare' function, will compare data pointer addresses * -- Returns NULL on failure * ============================================================================= */ list_t* TMlist_alloc (TM_ARGDECL comparator_t* comp) { list_t* listPtr = (list_t*)TM_MALLOC(sizeof(list_t)); if (listPtr == NULL) { return NULL; } listPtr->head.dataPtr = NULL; listPtr->head.nextPtr = NULL; listPtr->size = 0; if (comp == NULL) { listPtr->comparator = &default_list_comparator; /* default */ } else { listPtr->comparator = comp; } return listPtr; }
/* ============================================================================= * TMlist_alloc * -- If NULL passed for 'compare' function, will compare data pointer addresses * -- Returns NULL on failure * ============================================================================= */ list_t* TMlist_alloc (TM_ARGDECL long (*compare)(const void*, const void*)) { list_t* listPtr = (list_t*)TM_MALLOC(sizeof(list_t)); if (listPtr == NULL) { return NULL; } listPtr->head.dataPtr = NULL; listPtr->head.nextPtr = NULL; listPtr->size = 0; if (compare == NULL) { listPtr->compare = &compareDataPtrAddresses; /* default */ } else { listPtr->compare = compare; } return listPtr; }
TM_SAFE static node_t *new_node(val_t val, node_t *next, int transactional) { node_t *node; if (!transactional) { node = (node_t *)malloc(sizeof(node_t)); } else { node = (node_t *)TM_MALLOC(sizeof(node_t)); } if (node == NULL) { perror("malloc"); exit(1); } node->val = val; node->next = next; return node; }
TM_SAFE static node_t *new_node(val_t val, level_t level, int transactional) { node_t *node; if (!transactional) { node = (node_t *)malloc(sizeof(node_t) + level * sizeof(node_t *)); } else { node = (node_t *)TM_MALLOC(sizeof(node_t) + level * sizeof(node_t *)); } if (node == NULL) { perror("malloc"); exit(1); } node->val = val; node->level = level; return node; }
TM_SAFE static bucket_t *new_entry(val_t val, bucket_t *next, int transactional) { bucket_t *b; if (!transactional) { b = (bucket_t *)malloc(sizeof(bucket_t)); } else { b = (bucket_t *)TM_MALLOC(sizeof(bucket_t)); } if (b == NULL) { perror("malloc"); exit(1); } b->val = val; b->next = next; return b; }
/* ============================================================================= * TMelement_alloc * * Contains a copy of input arg 'coordinates' * ============================================================================= */ element_t* TMelement_alloc (TM_ARGDECL coordinate_t* coordinates, long numCoordinate) { element_t* elementPtr = NULL; elementPtr = (element_t*)TM_MALLOC(sizeof(element_t)); if (elementPtr) { long i; for (i = 0; i < numCoordinate; i++) { elementPtr->coordinates[i] = coordinates[i]; } elementPtr->numCoordinate = numCoordinate; minimizeCoordinates(elementPtr); checkAngles(elementPtr); calculateCircumCircle(elementPtr); initEdges(elementPtr, coordinates, numCoordinate); elementPtr->neighborListPtr = TMLIST_ALLOC(&element_listcompare); assert(elementPtr->neighborListPtr); elementPtr->isGarbage = false; elementPtr->isReferenced = false; } return elementPtr; }
_reservation_t* copy_reservation(TM_ARGDECL _reservation_t * _reservationPtr){ _reservation_t * _newReservationPtr = (_reservation_t *)TM_MALLOC(sizeof(_reservation_t)); memcpy((void *)_newReservationPtr, (void *)_reservationPtr, sizeof(_reservation_t)); return _newReservationPtr; }
/* ============================================================================= * TMgetNode * ============================================================================= */ static node_t* TMgetNode (TM_ARGDECL_ALONE) { node_t* n = (node_t*)TM_MALLOC(sizeof(*n)); return n; }
/* ============================================================================= * computeGraph * ============================================================================= */ void computeGraph (void* argPtr) { TM_THREAD_ENTER(); graph* GPtr = ((computeGraph_arg_t*)argPtr)->GPtr; graphSDG* SDGdataPtr = ((computeGraph_arg_t*)argPtr)->SDGdataPtr; long myId = thread_getId(); long numThread = thread_getNumThread(); ULONGINT_T j; ULONGINT_T maxNumVertices = 0; ULONGINT_T numEdgesPlaced = SDGdataPtr->numEdgesPlaced; /* * First determine the number of vertices by scanning the tuple * startVertex list */ long i; long i_start; long i_stop; createPartition(0, numEdgesPlaced, myId, numThread, &i_start, &i_stop); for (i = i_start; i < i_stop; i++) { if (SDGdataPtr->startVertex[i] > maxNumVertices) { maxNumVertices = SDGdataPtr->startVertex[i]; } } TM_BEGIN(); long tmp_maxNumVertices = (long)TM_SHARED_READ_L(global_maxNumVertices); long new_maxNumVertices = MAX(tmp_maxNumVertices, maxNumVertices) + 1; TM_SHARED_WRITE_L(global_maxNumVertices, new_maxNumVertices); TM_END(); thread_barrier_wait(); maxNumVertices = global_maxNumVertices; if (myId == 0) { GPtr->numVertices = maxNumVertices; GPtr->numEdges = numEdgesPlaced; GPtr->intWeight = SDGdataPtr->intWeight; GPtr->strWeight = SDGdataPtr->strWeight; for (i = 0; i < numEdgesPlaced; i++) { if (GPtr->intWeight[numEdgesPlaced-i-1] < 0) { GPtr->numStrEdges = -(GPtr->intWeight[numEdgesPlaced-i-1]) + 1; GPtr->numIntEdges = numEdgesPlaced - GPtr->numStrEdges; break; } } GPtr->outDegree = (LONGINT_T*)P_MALLOC((GPtr->numVertices) * sizeof(LONGINT_T)); assert(GPtr->outDegree); GPtr->outVertexIndex = (ULONGINT_T*)P_MALLOC((GPtr->numVertices) * sizeof(ULONGINT_T)); assert(GPtr->outVertexIndex); } thread_barrier_wait(); createPartition(0, GPtr->numVertices, myId, numThread, &i_start, &i_stop); for (i = i_start; i < i_stop; i++) { GPtr->outDegree[i] = 0; GPtr->outVertexIndex[i] = 0; } ULONGINT_T outVertexListSize = 0; thread_barrier_wait(); ULONGINT_T i0 = -1UL; for (i = i_start; i < i_stop; i++) { ULONGINT_T k = i; if ((outVertexListSize == 0) && (k != 0)) { while (i0 == -1UL) { for (j = 0; j < numEdgesPlaced; j++) { if (k == SDGdataPtr->startVertex[j]) { i0 = j; break; } } k--; } } if ((outVertexListSize == 0) && (k == 0)) { i0 = 0; } for (j = i0; j < numEdgesPlaced; j++) { if (i == GPtr->numVertices-1) { break; } if ((i != SDGdataPtr->startVertex[j])) { if ((j > 0) && (i == SDGdataPtr->startVertex[j-1])) { if (j-i0 >= 1) { outVertexListSize++; GPtr->outDegree[i]++; ULONGINT_T t; for (t = i0+1; t < j; t++) { if (SDGdataPtr->endVertex[t] != SDGdataPtr->endVertex[t-1]) { outVertexListSize++; GPtr->outDegree[i] = GPtr->outDegree[i]+1; } } } } i0 = j; break; } } if (i == GPtr->numVertices-1) { if (numEdgesPlaced-i0 >= 0) { outVertexListSize++; GPtr->outDegree[i]++; ULONGINT_T t; for (t = i0+1; t < numEdgesPlaced; t++) { if (SDGdataPtr->endVertex[t] != SDGdataPtr->endVertex[t-1]) { outVertexListSize++; GPtr->outDegree[i]++; } } } } } /* for i */ thread_barrier_wait(); prefix_sums(GPtr->outVertexIndex, GPtr->outDegree, GPtr->numVertices); thread_barrier_wait(); TM_BEGIN(); TM_SHARED_WRITE_L( global_outVertexListSize, ((long)TM_SHARED_READ_L(global_outVertexListSize) + outVertexListSize) ); TM_END(); thread_barrier_wait(); outVertexListSize = global_outVertexListSize; if (myId == 0) { GPtr->numDirectedEdges = outVertexListSize; GPtr->outVertexList = (ULONGINT_T*)P_MALLOC(outVertexListSize * sizeof(ULONGINT_T)); assert(GPtr->outVertexList); GPtr->paralEdgeIndex = (ULONGINT_T*)P_MALLOC(outVertexListSize * sizeof(ULONGINT_T)); assert(GPtr->paralEdgeIndex); GPtr->outVertexList[0] = SDGdataPtr->endVertex[0]; } thread_barrier_wait(); /* * Evaluate outVertexList */ i0 = -1UL; for (i = i_start; i < i_stop; i++) { ULONGINT_T k = i; while ((i0 == -1UL) && (k != 0)) { for (j = 0; j < numEdgesPlaced; j++) { if (k == SDGdataPtr->startVertex[j]) { i0 = j; break; } } k--; } if ((i0 == -1) && (k == 0)) { i0 = 0; } for (j = i0; j < numEdgesPlaced; j++) { if (i == GPtr->numVertices-1) { break; } if (i != SDGdataPtr->startVertex[j]) { if ((j > 0) && (i == SDGdataPtr->startVertex[j-1])) { if (j-i0 >= 1) { long ii = GPtr->outVertexIndex[i]; ULONGINT_T r = 0; GPtr->paralEdgeIndex[ii] = i0; GPtr->outVertexList[ii] = SDGdataPtr->endVertex[i0]; r++; ULONGINT_T t; for (t = i0+1; t < j; t++) { if (SDGdataPtr->endVertex[t] != SDGdataPtr->endVertex[t-1]) { GPtr->paralEdgeIndex[ii+r] = t; GPtr->outVertexList[ii+r] = SDGdataPtr->endVertex[t]; r++; } } } } i0 = j; break; } } /* for j */ if (i == GPtr->numVertices-1) { ULONGINT_T r = 0; if (numEdgesPlaced-i0 >= 0) { long ii = GPtr->outVertexIndex[i]; GPtr->paralEdgeIndex[ii+r] = i0; GPtr->outVertexList[ii+r] = SDGdataPtr->endVertex[i0]; r++; ULONGINT_T t; for (t = i0+1; t < numEdgesPlaced; t++) { if (SDGdataPtr->endVertex[t] != SDGdataPtr->endVertex[t-1]) { GPtr->paralEdgeIndex[ii+r] = t; GPtr->outVertexList[ii+r] = SDGdataPtr->endVertex[t]; r++; } } } } } /* for i */ thread_barrier_wait(); if (myId == 0) { P_FREE(SDGdataPtr->startVertex); P_FREE(SDGdataPtr->endVertex); GPtr->inDegree = (LONGINT_T*)P_MALLOC(GPtr->numVertices * sizeof(LONGINT_T)); assert(GPtr->inDegree); GPtr->inVertexIndex = (ULONGINT_T*)P_MALLOC(GPtr->numVertices * sizeof(ULONGINT_T)); assert(GPtr->inVertexIndex); } thread_barrier_wait(); for (i = i_start; i < i_stop; i++) { GPtr->inDegree[i] = 0; GPtr->inVertexIndex[i] = 0; } /* A temp. array to store the inplied edges */ ULONGINT_T* impliedEdgeList; if (myId == 0) { impliedEdgeList = (ULONGINT_T*)P_MALLOC(GPtr->numVertices * MAX_CLUSTER_SIZE * sizeof(ULONGINT_T)); global_impliedEdgeList = impliedEdgeList; } thread_barrier_wait(); impliedEdgeList = global_impliedEdgeList; createPartition(0, (GPtr->numVertices * MAX_CLUSTER_SIZE), myId, numThread, &i_start, &i_stop); for (i = i_start; i < i_stop; i++) { impliedEdgeList[i] = 0; } /* * An auxiliary array to store implied edges, in case we overshoot * MAX_CLUSTER_SIZE */ ULONGINT_T** auxArr; if (myId == 0) { auxArr = (ULONGINT_T**)P_MALLOC(GPtr->numVertices * sizeof(ULONGINT_T*)); assert(auxArr); global_auxArr = auxArr; } thread_barrier_wait(); auxArr = global_auxArr; createPartition(0, GPtr->numVertices, myId, numThread, &i_start, &i_stop); for (i = i_start; i < i_stop; i++) { /* Inspect adjacency list of vertex i */ for (j = GPtr->outVertexIndex[i]; j < (GPtr->outVertexIndex[i] + GPtr->outDegree[i]); j++) { ULONGINT_T v = GPtr->outVertexList[j]; ULONGINT_T k; for (k = GPtr->outVertexIndex[v]; k < (GPtr->outVertexIndex[v] + GPtr->outDegree[v]); k++) { if (GPtr->outVertexList[k] == i) { break; } } if (k == GPtr->outVertexIndex[v]+GPtr->outDegree[v]) { TM_BEGIN(); /* Add i to the impliedEdgeList of v */ long inDegree = (long)TM_SHARED_READ_L(GPtr->inDegree[v]); TM_SHARED_WRITE_L(GPtr->inDegree[v], (inDegree + 1)); if (inDegree < MAX_CLUSTER_SIZE) { TM_SHARED_WRITE_L(impliedEdgeList[v*MAX_CLUSTER_SIZE+inDegree], i); } else { /* Use auxiliary array to store the implied edge */ /* Create an array if it's not present already */ ULONGINT_T* a = NULL; if ((inDegree % MAX_CLUSTER_SIZE) == 0) { a = (ULONGINT_T*)TM_MALLOC(MAX_CLUSTER_SIZE * sizeof(ULONGINT_T)); assert(a); TM_SHARED_WRITE_P(auxArr[v], a); } else { a = auxArr[v]; } TM_SHARED_WRITE_L(a[inDegree % MAX_CLUSTER_SIZE], i); } TM_END(); } } } /* for i */ thread_barrier_wait(); prefix_sums(GPtr->inVertexIndex, GPtr->inDegree, GPtr->numVertices); if (myId == 0) { GPtr->numUndirectedEdges = GPtr->inVertexIndex[GPtr->numVertices-1] + GPtr->inDegree[GPtr->numVertices-1]; GPtr->inVertexList = (ULONGINT_T *)P_MALLOC(GPtr->numUndirectedEdges * sizeof(ULONGINT_T)); } thread_barrier_wait(); /* * Create the inVertex List */ for (i = i_start; i < i_stop; i++) { for (j = GPtr->inVertexIndex[i]; j < (GPtr->inVertexIndex[i] + GPtr->inDegree[i]); j++) { if ((j - GPtr->inVertexIndex[i]) < MAX_CLUSTER_SIZE) { GPtr->inVertexList[j] = impliedEdgeList[i*MAX_CLUSTER_SIZE+j-GPtr->inVertexIndex[i]]; } else { GPtr->inVertexList[j] = auxArr[i][(j-GPtr->inVertexIndex[i]) % MAX_CLUSTER_SIZE]; } } } thread_barrier_wait(); if (myId == 0) { P_FREE(impliedEdgeList); } for (i = i_start; i < i_stop; i++) { if (GPtr->inDegree[i] > MAX_CLUSTER_SIZE) { P_FREE(auxArr[i]); } } thread_barrier_wait(); if (myId == 0) { P_FREE(auxArr); } TM_THREAD_EXIT(); }
/* ============================================================================= * TMdecoder_process * ============================================================================= */ int_error_t TMdecoder_process (TM_ARGDECL decoder_t* decoderPtr, char* bytes, long numByte) { bool_t status; /* * Basic error checking */ if (numByte < (long)PACKET_HEADER_LENGTH) { return ERROR_SHORT; } packet_t* packetPtr = (packet_t*)bytes; long flowId = packetPtr->flowId; long fragmentId = packetPtr->fragmentId; long numFragment = packetPtr->numFragment; long length = packetPtr->length; if (flowId < 0) { return ERROR_FLOWID; } if ((fragmentId < 0) || (fragmentId >= numFragment)) { return ERROR_FRAGMENTID; } if (length < 0) { return ERROR_LENGTH; } #if 0 /* * With the above checks, this one is redundant */ if (numFragment < 1) { return ERROR_NUMFRAGMENT; } #endif /* * Add to fragmented map for reassembling */ if (numFragment > 1) { MAP_T* fragmentedMapPtr = decoderPtr->fragmentedMapPtr; list_t* fragmentListPtr = (list_t*)TMMAP_FIND(fragmentedMapPtr, (void*)flowId); if (fragmentListPtr == NULL) { fragmentListPtr = TMLIST_ALLOC(&decoder_comparator); assert(fragmentListPtr); status = TMLIST_INSERT(fragmentListPtr, (void*)packetPtr); assert(status); status = TMMAP_INSERT(fragmentedMapPtr, (void*)flowId, (void*)fragmentListPtr); assert(status); } else { list_iter_t it; TMLIST_ITER_RESET(&it, fragmentListPtr); assert(TMLIST_ITER_HASNEXT(&it, fragmentListPtr)); packet_t* firstFragmentPtr = (packet_t*)TMLIST_ITER_NEXT(&it, fragmentListPtr); long expectedNumFragment = firstFragmentPtr->numFragment; if (numFragment != expectedNumFragment) { status = TMMAP_REMOVE(fragmentedMapPtr, (void*)flowId); assert(status); return ERROR_NUMFRAGMENT; } status = TMLIST_INSERT(fragmentListPtr, (void*)packetPtr); assert(status); /* * If we have all the fragments we can reassemble them */ if (TMLIST_GETSIZE(fragmentListPtr) == numFragment) { long numByte = 0; long i = 0; TMLIST_ITER_RESET(&it, fragmentListPtr); while (TMLIST_ITER_HASNEXT(&it, fragmentListPtr)) { packet_t* fragmentPtr = (packet_t*)TMLIST_ITER_NEXT(&it, fragmentListPtr); if(fragmentPtr->flowId != flowId) printf("fragflow %lx floId %lx\n", fragmentPtr->flowId, flowId); assert(fragmentPtr->flowId == flowId); if (fragmentPtr->fragmentId != i) { status = TMMAP_REMOVE(fragmentedMapPtr, (void*)flowId); assert(status); return ERROR_INCOMPLETE; /* should be sequential */ } numByte += fragmentPtr->length; i++; } char* data = (char*)TM_MALLOC(numByte + 1); assert(data); data[numByte] = '\0'; char* dst = data; TMLIST_ITER_RESET(&it, fragmentListPtr); while (TMLIST_ITER_HASNEXT(&it, fragmentListPtr)) { packet_t* fragmentPtr = (packet_t*)TMLIST_ITER_NEXT(&it, fragmentListPtr); memcpy(dst, (void*)fragmentPtr->data, fragmentPtr->length); dst += fragmentPtr->length; } assert(dst == data + numByte); decoded_t* decodedPtr = (decoded_t*)TM_MALLOC(sizeof(decoded_t)); assert(decodedPtr); decodedPtr->flowId = flowId; decodedPtr->data = data; queue_t* decodedQueuePtr = decoderPtr->decodedQueuePtr; status = TMQUEUE_PUSH(decodedQueuePtr, (void*)decodedPtr); assert(status); TMLIST_FREE(fragmentListPtr); status = TMMAP_REMOVE(fragmentedMapPtr, (void*)flowId); assert(status); } } } else { /* * This is the only fragment, so it is ready */ if (fragmentId != 0) { return ERROR_FRAGMENTID; } char* data = (char*)TM_MALLOC(length + 1); assert(data); data[length] = '\0'; memcpy(data, (void*)packetPtr->data, length); decoded_t* decodedPtr = (decoded_t*)TM_MALLOC(sizeof(decoded_t)); assert(decodedPtr); decodedPtr->flowId = flowId; decodedPtr->data = data; queue_t* decodedQueuePtr = decoderPtr->decodedQueuePtr; status = TMQUEUE_PUSH(decodedQueuePtr, (void*)decodedPtr); assert(status); } return ERROR_NONE; }