// // Test the lock-free implementations. // int main() { // // Test CAS and CAS2 // Test_CAS_assembly(); Test_CAS_intrinsic(); Test_CAS_windows(); Test_CAS2_assembly(); Test_CAS2_intrinsic(); Test_CAS2_windows(); // // Test Lock-free Stack // StressStack<TEST_TYPE, 4096>()(); // Demo the stack node<MyStruct> Nodes[10]; LockFreeStack<MyStruct> stack; stack.Push(&Nodes[1]); stack.Pop(); // returns &Nodes[1] stack.Pop(); // returns nullptr // // Test Lock-free Queue // std::vector<node<TEST_TYPE> *> apNodes(StressQueue<TEST_TYPE, 4096>::cNodes * 4096 + 1); // 4096 threads, and 1 extra dummy node std::for_each(std::begin(apNodes), std::end(apNodes), CreateNode<TEST_TYPE>); StressQueue<TEST_TYPE, 4096> theQueue(apNodes); theQueue(); std::for_each(std::begin(apNodes), std::end(apNodes), DeleteNode<TEST_TYPE>); // Demo the queue LockFreeQueue<MyStruct> queue(&Nodes[0]); // Nodes[0] is dummy node queue.Add(&Nodes[1]); queue.Remove(); // returns &Nodes[1] queue.Remove(); // returns nullptr; // // Demonstrate Lock-free Freelist // Demo_Freelist(); return 0; }
void statisticsNetwork::dijkstra( vector<baseType>& distance, network::nodeList vl, unsigned int v ) { dijkstraCompare dC; relaxed_heap <nodeDescriptor, dijkstraCompare > theQueue (vl.size()+3, dC); dC.weightMap.resize(vl.size()); unsigned int i; for( i=0 ; i<vl.size() ; i++ ) dC.weightMap[i] = numeric_limits<baseType>::infinity(); dC.weightMap[ v-*vl.begin() ]=0; nodeDescriptor j, k; double d; theQueue.push ( v+1 -*vl.begin() ); // um nicht 0 zu pushen sind die Knotennrn in theQueue um 1 verschoben while (!theQueue.empty()) { j = theQueue.top()-1 +*vl.begin(); theQueue.pop(); for (node::edgeDescriptor l=0 ; l < node::theNodes[j]->degree() ; l++ ) { k = node::theNodes[j]->getTarget(l)->getNumber(); // alle Nachbarn k von j d = 1/(node::theNodes[j]->getWeight(l)); // d misst die Entfernung zwischen k und j if ( (dC.weightMap[ j-*vl.begin() ] + d) < dC.weightMap[ k-*vl.begin() ] && dC.weightMap[ k-*vl.begin() ] == numeric_limits<baseType>::infinity() ) { dC.weightMap[ k-*vl.begin() ] = dC.weightMap[ j-*vl.begin() ] + d; theQueue.push( k+1-*vl.begin() ); } else if ( (dC.weightMap[ j-*vl.begin() ] + d) < dC.weightMap[ k-*vl.begin() ] && dC.weightMap[ k-*vl.begin() ] < numeric_limits<baseType>::infinity() ) { dC.weightMap[ k-*vl.begin() ] = dC.weightMap[ j-*vl.begin() ] + d; theQueue.update( k+1-*vl.begin() ); } } } for( i=0 ; i<vl.size() ; i++) distance[i] = dC.weightMap[i]; }