I'm getting some strange errors on a USACO training problem (clocks). I suspect that I'm accessing memory out of bounds somewhere in my code, but I can't figure out where...
Errors
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0.000 secs, 3356 KB]
Test 2: TEST OK [0.000 secs, 3356 KB]
Test 3: TEST OK [0.281 secs, 9032 KB]
Test 4: TEST OK [0.659 secs, 14708 KB]
> Run 5: Execution error: Your program had this runtime error:
Illegal file open (/sys/devices/system/cpu/online). The program
ran for 0.767 CPU seconds before the error. It used 16292 KB of
memory.
------ Data for Run 5 [length=26 bytes] ------
6 12 12 12 12 12 12 12 12 ----------------------------
Test 5: SIGNAL 50 (0.767 secs, 16292 KB)
My Code:
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>
#define ord(ch) ((int)(ch - 'A'))
using namespace std;
> I'm getting some strange errors on a USACO training problem (clocks). I suspect that I'm accessing memory out of bounds somewhere in my code, but I can't figure out where...
> Errors
> Compiling...
> Compile: OK
> Executing...
> Test 1: TEST OK [0.000 secs, 3356 KB]
> Test 2: TEST OK [0.000 secs, 3356 KB]
> Test 3: TEST OK [0.281 secs, 9032 KB]
> Test 4: TEST OK [0.659 secs, 14708 KB]
> > Run 5: Execution error: Your program had this runtime error:
> Illegal file open (/sys/devices/system/cpu/online). The program
> ran for 0.767 CPU seconds before the error. It used 16292 KB of
> memory.
> ------ Data for Run 5 [length=26 bytes] ------
> 6 12 12
> 12 12 12
> 12 12 12
> ----------------------------
> Test 5: SIGNAL 50 (0.767 secs, 16292 KB)
> By the way the code functions fine (gets the right answers), but seems to cause memory errors. Thanks for your time!
> --Kuroneko
I'm not an expert enough to figure out the exact problem,
but when I have a problem like that I generally put in a pause
at the place where the problem may be occurring, then step
through it one command at a time and check the values of
the iterators to see where one of them oversteps the bounds
of the vector.
That is assuming that the problem is someplace in one of the
loops, which is where I usually have that kind of problem.
Kuroneko <zeng.aaro...@gmail.com> writes:
> I'm getting some strange errors on a USACO training problem (clocks).
> I suspect that I'm accessing memory out of bounds somewhere in my
> code, but I can't figure out where...
A link to the problem (or a description of it would help). It's not
going to help diagnose the issue, but it help people feel interested!
> Executing...
> Test 1: TEST OK [0.000 secs, 3356 KB]
> Test 2: TEST OK [0.000 secs, 3356 KB]
> Test 3: TEST OK [0.281 secs, 9032 KB]
> Test 4: TEST OK [0.659 secs, 14708 KB]
> > Run 5: Execution error: Your program had this runtime error:
> Illegal file open (/sys/devices/system/cpu/online). The program
> ran for 0.767 CPU seconds before the error. It used 16292 KB of
> memory.
> ------ Data for Run 5 [length=26 bytes] ------
> 6 12 12 > 12 12 12 > 12 12 12 > ----------------------------
> Test 5: SIGNAL 50 (0.767 secs, 16292 KB)
> My Code:
<snip code>
> By the way the code functions fine (gets the right answers), but seems
> to cause memory errors.
What makes you think this? I ran the test case in question under
valgrind (a memory checker) and it reported no problems. That's not
foolproof but it is string evidence.
> I'm getting some strange errors on a USACO training problem (clocks).
> I suspect that I'm accessing memory out of bounds somewhere in my
> code, but I can't figure out where...
> Errors
> Compiling...
> Compile: OK
> Executing...
> Test 1: TEST OK [0.000 secs, 3356 KB]
> Test 2: TEST OK [0.000 secs, 3356 KB]
> Test 3: TEST OK [0.281 secs, 9032 KB]
> Test 4: TEST OK [0.659 secs, 14708 KB]
> > Run 5: Execution error: Your program had this runtime error:
> Illegal file open (/sys/devices/system/cpu/online). The program
> ran for 0.767 CPU seconds before the error. It used 16292 KB of
> memory.
The error message does not seem to indicate that memory is accessed
out of bounds. Could it be that there are constraints being put on
the cpu time usage and/or memory usage of the running program, and
that the program hits one of these limits when computing the solution
for run 5?
> I'm getting some strange errors on a USACO training problem (clocks). I suspect that I'm accessing memory out of bounds somewhere in my code, but I can't figure out where...
There don't appear to be any out of bounds accesses in your code.
But..
> vector<int> move(vector<int> v, int n)
> {
> for (string::iterator it = moves[n].begin(); it< moves[n].end(); ++it)
On Sunday, 14 October 2012 17:14:56 UTC-4, Ike Naar wrote:
> The error message does not seem to indicate that memory is accessed
> out of bounds. Could it be that there are constraints being put on
> the cpu time usage and/or memory usage of the running program, and
> that the program hits one of these limits when computing the solution
> for run 5?
The time usage bound is 1 sec, so that's probably not the problem, but I may be using too much memory; I'll look into that.
> I'm getting some strange errors on a USACO training problem (clocks).
I suspect that I'm accessing memory out of bounds somewhere in my code,
but I can't figure out where...
> Errors
It seems that the amount of memory used after each TEST increases by 5676 bytes. Assuming that there is a maximum amount of memory of 16384 (i.e. 2^14) then the error message is generated when the next memory request takes your program pass its permitted limit.
Note that there is little purpose in providing only part of the code without any explanation as to what it is supposed to do. If this code is written by you then you have other problems. If it was largely written by someone else then find another teacher.