simple C program crashes at run time
#include stdio.h #include stdlib.h #include string.h #define TAGLIA 415 main() { int i, j, k, iran; unsigned int seed; float unran; float mata[TAGLIA][TAGLIA], matb[TAGLIA][TAGLIA], matc[TAGLIA][TAGLIA]; srand(seed); printf(init start...\n); /* this should init all elements with pseudo-random float values */ for(i=0;iTAGLIA;i++) { for(j=0;jTAGLIA;j++) { iran=rand(); unran = iran / 1.0E10; mata[i][j]=unran; iran=rand(); unran = iran / 1.0E10; matb[i][j]=unran; matc[i][j] = 0.0; } } printf(init end.\n); /* do something to grab cpu-time */ for(i=0;iTAGLIA;i++) { for(j=0;jTAGLIA;j++) { for (k=0;kTAGLIA;k++) matc[i][j]=matc[i][j]+mata[i][k]*matb[k][j]; } } printf(all done.\n); } No informational and/or warnings while building it: gcc unlucky.c -o unlucky.exe It works for TAGLIA 416 With TAGLIA = 416 it looks unusually fast and without outputs with TAGLIA 416 it crashes: [EMAIL PROTECTED] ~ $ ./unlucky.exe Segmentation fault (core dumped) $ more unlucky.exe.stackdump Exception: STATUS_STACK_OVERFLOW at eip=00401593 eax=1774 ebx=0004 ecx=00032064 edx=00401098 esi=610F3060 edi=61005AC0 ebp=0022F068 esp=0022F05C program=d:\cygwin\home\sysnaz\unlucky.exe, pid 1232, thread main cs=001B ds=0023 es=0023 fs=0038 gs= ss=0023 Stack trace: Frame Function Args 0022F068 00401593 (0001, 616D5310, 0A0500A8, 0022F0C0) 0022F0A8 61005F54 (0022F0C0, , , ) 0022FF88 6100616B (, , , ) End of stack trace What does it happen? the same code built on linux doesn't crashes.. Thanks in advance for help. bye. -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/
Re: simple C program crashes at run time
On Aug 12 12:47, [EMAIL PROTECTED] wrote: #include stdio.h #include stdlib.h #include string.h #define TAGLIA 415 main() { int i, j, k, iran; unsigned int seed; float unran; float mata[TAGLIA][TAGLIA], matb[TAGLIA][TAGLIA], matc[TAGLIA][TAGLIA]; Your local data is too big for the default stack size of 2 Megs when you're setting TAGLIA to a value = 416. Try e. g. gcc -Wl,--stack=300 unlucky.c -o unlucky Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Co-Project Leader mailto:[EMAIL PROTECTED] Red Hat, Inc. -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/
Re: simple C program crashes at run time
Hallo user, Am Donnerstag, 12. August 2004 um 12:47 schriebst du: #include stdio.h #include stdlib.h #include string.h #define TAGLIA 415 main() { int i, j, k, iran; unsigned int seed; float unran; float mata[TAGLIA][TAGLIA], matb[TAGLIA][TAGLIA], matc[TAGLIA][TAGLIA]; srand(seed); printf(init start...\n); /* this should init all elements with pseudo-random float values */ for(i=0;iTAGLIA;i++) { for(j=0;jTAGLIA;j++) { iran=rand(); unran = iran / 1.0E10; mata[i][j]=unran; iran=rand(); unran = iran / 1.0E10; matb[i][j]=unran; matc[i][j] = 0.0; } } printf(init end.\n); /* do something to grab cpu-time */ for(i=0;iTAGLIA;i++) { for(j=0;jTAGLIA;j++) { for (k=0;kTAGLIA;k++) matc[i][j]=matc[i][j]+mata[i][k]*matb[k][j]; } } printf(all done.\n); } No informational and/or warnings while building it: gcc unlucky.c -o unlucky.exe It works for TAGLIA 416 With TAGLIA = 416 it looks unusually fast and without outputs with TAGLIA 416 it crashes: [EMAIL PROTECTED] ~ $ ./unlucky.exe Segmentation fault (core dumped) $ more unlucky.exe.stackdump Exception: STATUS_STACK_OVERFLOW at eip=00401593 eax=1774 ebx=0004 ecx=00032064 edx=00401098 esi=610F3060 edi=61005AC0 ebp=0022F068 esp=0022F05C program=d:\cygwin\home\sysnaz\unlucky.exe, pid 1232, thread main cs=001B ds=0023 es=0023 fs=0038 gs= ss=0023 Stack trace: Frame Function Args 0022F068 00401593 (0001, 616D5310, 0A0500A8, 0022F0C0) 0022F0A8 61005F54 (0022F0C0, , , ) 0022FF88 6100616B (, , , ) End of stack trace What does it happen? the same code built on linux doesn't crashes.. See stackdump: STATUS_STACK_OVERFLOW Thanks in advance for help. bye. Increase the stack (only possible during buildtime): $ gcc -o unlucky unlucky.c -Wl,--stack,8388608 $ ./unlucky.exe init start... init end. all done. Gerrit -- =^..^= -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/
RE: simple C program crashes at run time
-Original Message- From: cygwin-owner On Behalf Of user Sent: 12 August 2004 11:48 #define TAGLIA 415 main() { int i, j, k, iran; unsigned int seed; float unran; float mata[TAGLIA][TAGLIA], matb[TAGLIA][TAGLIA], matc[TAGLIA][TAGLIA]; 1 float == 4 bytes. 415 * 415 == 172225 elements 3 arrays * 415^2 elements each * 4 bytes == 2066700 bytes I believe that's a bit large for the stack. It works for TAGLIA 416 With TAGLIA = 416 it looks unusually fast and without outputs with TAGLIA 416 it crashes: [EMAIL PROTECTED] ~ $ ./unlucky.exe Segmentation fault (core dumped) $ more unlucky.exe.stackdump Exception: STATUS_STACK_OVERFLOW at eip=00401593 And indeed, the system agrees with me. What does it happen? the same code built on linux doesn't crashes.. Linux and 'doze reserve different amounts of memory space for the stack when a task starts up (to be precise, when a thread starts up within a task). In particular, the default stack size for a newly-created thread under windoze is 1Mb, which is less than half what you'd need for those arrays. See http://www.google.com/search?hl=enie=UTF-8q=increase+default+thread+stack+ size+site%3Acygwin.com for masses more information. In particular, you may need to recompile your application with the -Wl,--stack,some big number argument. Here's an example. I took your code and removed the #define TAGLIA, so I could pass it in as a commandline -D flag: [EMAIL PROTECTED] /davek/test/cygstack cat telle.c #include stdio.h #include stdlib.h #include string.h main() { int i, j, k, iran; unsigned int seed; float unran; float mata[TAGLIA][TAGLIA], matb[TAGLIA][TAGLIA], matc[TAGLIA][TAGLIA]; srand(seed); printf(init start...\n); /* this should init all elements with pseudo-random float values */ for(i=0;iTAGLIA;i++) { for(j=0;jTAGLIA;j++) { iran=rand(); unran = iran / 1.0E10; mata[i][j]=unran; iran=rand(); unran = iran / 1.0E10; matb[i][j]=unran; matc[i][j] = 0.0; } } printf(init end.\n); /* do something to grab cpu-time */ for(i=0;iTAGLIA;i++) { for(j=0;jTAGLIA;j++) { for (k=0;kTAGLIA;k++) matc[i][j]=matc[i][j]+mata[i][k]*matb[k][j]; } } printf(all done.\n); } [EMAIL PROTECTED] /davek/test/cygstack gcc -o unlucky -DTAGLIA=410 telle.c [EMAIL PROTECTED] /davek/test/cygstack ./unlucky.exe init start... init end. all done. [EMAIL PROTECTED] /davek/test/cygstack gcc -o unlucky -DTAGLIA=411 telle.c [EMAIL PROTECTED] /davek/test/cygstack ./unlucky.exe Segmentation fault (core dumped) [EMAIL PROTECTED] /davek/test/cygstack gcc -o unlucky -DTAGLIA=411 telle.c -Wl,--stack,8 192000 [EMAIL PROTECTED] /davek/test/cygstack ./unlucky.exe init start... init end. all done. [EMAIL PROTECTED] /davek/test/cygstack gcc -o unlucky -DTAGLIA=444 telle.c -Wl,--stack,8 192000 [EMAIL PROTECTED] /davek/test/cygstack ./unlucky.exe init start... init end. all done. [EMAIL PROTECTED] /davek/test/cygstack gcc -o unlucky -DTAGLIA=444 telle.c [EMAIL PROTECTED] /davek/test/cygstack ./unlucky.exe Segmentation fault (core dumped) [EMAIL PROTECTED] /davek/test/cygstack As you can see, for reasons probably relating to different environment variable size, I can only get up to 410 before I get errors; adding the --stack option fixes it. cheers, DaveK -- Can't think of a witty .sigline today -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/