Subway icon indicating copy to clipboard operation
Subway copied to clipboard

little bug

Open kevinsouthxu opened this issue 3 years ago • 10 comments

After running with a simple graph,a segmentation fault occurred check the graph.cu I found that in line 156

                        uint *outDegreeCounter  = new uint[num_nodes];
			uint location;  
			for(uint i=0; i<num_edges; i++)
			{
				location = nodePointer[edges[i].source] + outDegreeCounter[edges[i].source];
				edgeList[location].end = edges[i].end;
				//if(isWeighted)
				//	edgeList[location].w8 = edges[i].w8;
				outDegreeCounter[edges[i].source]++;  
			}

The outDegreeCounter array should be initialized

kevinsouthxu avatar Feb 16 '22 06:02 kevinsouthxu

my cuda version is 10.0

kevinsouthxu avatar Feb 16 '22 06:02 kevinsouthxu

for (uint i = 0; i < num_nodes; i++) outDegreeCounter[i] = 0;

@amirnodehi you're not initializing the array, it can contain random values, there are no guarantees that it is initialized to zero

TiagoMAntunes avatar Feb 27 '22 21:02 TiagoMAntunes

==7724==    at 0x12509A: void dynamic<OutEdge>(unsigned int, unsigned int, unsigned int, unsigned int*, unsigned int*, unsigned int*, unsigned int*, OutEdge*, OutEdge*) (in /mnt/efs/fs1/Subway/pr-sync)
==7724==    by 0x125687: std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)(unsigned int, unsigned int, unsigned int, unsigned int*, unsigned int*, unsigned int*, unsigned int*, OutEdge*, OutEdge*), unsigned int, unsigned int, unsigned int, unsigned int*, unsigned int*, unsigned int*, unsigned int*, OutEdge*, OutEdge*> > >::_M_run() (in /mnt/efs/fs1/Subway/pr-sync)
==7724==    by 0x4938B2E: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.25)
==7724==    by 0x485EFA2: start_thread (pthread_create.c:486)
==7724== 
==7724== Conditional jump or move depends on uninitialised value(s)
==7724==    at 0x1250BA: void dynamic<OutEdge>(unsigned int, unsigned int, unsigned int, unsigned int*, unsigned int*, unsigned int*, unsigned int*, OutEdge*, OutEdge*) (in /mnt/efs/fs1/Subway/pr-sync)
==7724==    by 0x125687: std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)(unsigned int, unsigned int, unsigned int, unsigned int*, unsigned int*, unsigned int*, unsigned int*, OutEdge*, OutEdge*), unsigned int, unsigned int, unsigned int, unsigned int*, unsigned int*, unsigned int*, unsigned int*, OutEdge*, OutEdge*> > >::_M_run() (in /mnt/efs/fs1/Subway/pr-sync)
==7724==    by 0x4938B2E: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.25)
==7724==    by 0x485EFA2: start_thread (pthread_create.c:486)

Just a heads up, seems like there are more problems throughout the rest of the code

TiagoMAntunes avatar Feb 27 '22 22:02 TiagoMAntunes

@TiagoMAntunes After initializing the array it can work normally

kevinsouthxu avatar Feb 28 '22 10:02 kevinsouthxu

@kevinsouthxu there are more problems in the code, you can check my solution

TiagoMAntunes avatar Feb 28 '22 11:02 TiagoMAntunes

@TiagoMAntunes In fact, some operations in your code are unnecessary. the original code:

for(uint i=1; i<num_nodes-1; i++)
        outDegree[i-1] = nodePointer[i] - nodePointer[i-1];
outDegree[num_nodes-1] = num_edges - nodePointer[num_nodes-1];

and yours:

for(uint i=1; i<num_nodes; i++)
	outDegree[i-1] = nodePointer[i] - nodePointer[i-1];
outDegree[num_nodes-1] = num_edges - nodePointer[num_nodes-1];

The third line actually calculate the last element in the array of outDegree, and your code add one unnecessary iteration.

kevinsouthxu avatar Feb 28 '22 11:02 kevinsouthxu

@kevinsouthxu No it does not. The range is [1,num_nodes-1) -> [1,num_nodes-2] but inside you work with outDegree[i-1] which means you're actually using the range [0,num_nodes-3]

Then at the end, he does outDegree[num_nodes-1] which means that position num_nodes-2 is skipped. I tested it on GDB, you can go ahead and check it yourself

TiagoMAntunes avatar Feb 28 '22 11:02 TiagoMAntunes

@TiagoMAntunes you are right! Now I'm starting to wonder why this code runs correctly on my computer.

kevinsouthxu avatar Feb 28 '22 11:02 kevinsouthxu

@kevinsouthxu it was actually running fine on mine too, but it's by luck since it's undefined behaviour. You should run tools such as valgrind or compute-sanitizer (the latter is available in the CUDA toolkit) to detect incorrect usage of memory

TiagoMAntunes avatar Feb 28 '22 11:02 TiagoMAntunes

@TiagoMAntunes Alright. Thank you for reminding me!

kevinsouthxu avatar Feb 28 '22 11:02 kevinsouthxu