Computer Science Canada How to set memory limits for judging a program? |
Author: | Dratino [ Wed Apr 13, 2011 8:28 pm ] |
Post subject: | How to set memory limits for judging a program? |
I recently coded what I think is a successful solution to IOI 2004 Problem 1.1 (Artemis), but I have no idea how to test whether the memory usage is under a certain cutoff (by that IOI's standards, 16 MB). I see something about setrlimit() when I search for it on the Internet, but it seems to have to be applied within the program. |
Author: | Tony [ Wed Apr 13, 2011 8:34 pm ] |
Post subject: | RE:How to set memory limits for judging a program? |
You can use a profiler to measure the memory usage during execution. The exact tools would be language and platform specific. |
Author: | Dratino [ Wed Apr 13, 2011 8:55 pm ] |
Post subject: | RE:How to set memory limits for judging a program? |
I'm using Ubuntu Linux, and Valgrind seems to be the tool for profiling. Well, I got the profiler running, and the max memory used was about 350 KB. But how would I actually limit the memory used so that the program would return a bad_alloc error when exceeding the memory limit like it does on TopCoder? |
Author: | Alexander_ [ Fri Apr 15, 2011 3:40 am ] | ||
Post subject: | Re: How to set memory limits for judging a program? | ||
Hello, You can utilize the ulimit command that should be built in to the BASH shell, i.e.
This will effectively limit child processes of the shell to have a limit of 16 megabytes of virtual memory (v) and resident set size (m) throwing the appropriate errors with a heap alloc of greater size. You can read more about the function in its man page: http://ss64.com/bash/ulimit.html |
Author: | Dratino [ Fri Apr 15, 2011 10:04 pm ] |
Post subject: | RE:How to set memory limits for judging a program? |
Thanks a lot, that seems to be a working solution. Would there be a solution for just limiting the memory usage of a single program? |
Author: | bbi5291 [ Sat Apr 16, 2011 12:29 am ] |
Post subject: | Re: RE:How to set memory limits for judging a program? |
Dratino @ Fri Apr 15, 2011 10:04 pm wrote: Thanks a lot, that seems to be a working solution.
Bash script.
Would there be a solution for just limiting the memory usage of a single program? Or just use our judge. |