Hi, I have following sorting program... basically it will split the large files into small file and creates thread..each thread will sort files after that merge back all sorted files...
this program works fine on single CPU machine... same program giving problem on 8 CPU machine... the problem is , after creating the thread.... one of the thread finishes the job... all other threads are still working.... as soon as one thread finishes the job, i am getting perl application error (pops up small window) popup window contains following message... ====== perl.exe application errorr The instruction at "0x2808335c" referenced memory at "0x00000004". The memory couldn't be written ======= follwoing is output -------- D:\Madhu\Sort_tmp>perl sort_new1.pl Thu Feb 27 14:37:00 2003 thread 1 Sorting chunk : tmp_1.txt Thu Feb 27 14:37:00 2003 thread 2 Sorting chunk : tmp_2.txt Thu Feb 27 14:37:00 2003 thread 3 Sorting chunk : tmp_3.txt Thu Feb 27 14:37:01 2003 thread 4 Sorting chunk : tmp_4.txt Thu Feb 27 14:37:05 2003 thread 5 Sorting chunk : tmp_5.txt Thu Feb 27 14:37:11 2003 thread 6 Sorting chunk : tmp_6.txt Thu Feb 27 14:37:17 2003 thread 7 Sorting chunk : tmp_7.txt Thu Feb 27 14:37:25 2003 thread 8 Sorting chunk : tmp_8.txt Thu Feb 27 14:37:34 2003 thread 9 Sorting chunk : tmp_9.txt Thu Feb 27 14:37:42 2003 thread 10 Sorting chunk : tmp_10.txt Thu Feb 27 14:37:51 2003 thread 11 Sorting chunk : tmp_11.txt Thu Feb 27 14:38:02 2003 thread 12 Sorting chunk : tmp_12.txt Thu Feb 27 14:38:14 2003 thread 13 Sorting chunk : tmp_13.txt Thu Feb 27 14:38:26 2003 thread 14 Sorting chunk : tmp_14.txt Thu Feb 27 14:38:44 2003 thread 14 Sorting chunk : tmp_14.txt COMPLETED ************** here i am getting error ..following is message perl.exe application errorr The instruction at "0x2808335c" referenced memory at "0x00000004". The memory couldn't be written *************** ---------------- any body have any idea ? following is my script ++++++++++++++++++++++ #!C:\perl_5.8\bin\perl -w #use strict; use threads; use threads::shared; my $counter = 0; my @tmp_files; my @buffer; my %bounds:shared = (); my $i = 0; my $tm1 = &my_time(); my $file = 'D:\Madhu\Tmp\abi_feeder.dat'; open(FILE,$file) || die $!; while(<FILE>){ push(@buffer,$_); if(@buffer > 1000000){ $counter++; my $tmp = "tmp_$counter.txt"; open(TMP,">$tmp") || die $!; for(@buffer){ print TMP $_; } close(TMP); push(@tmp_files,$tmp); @buffer = (); } } if(@buffer){ my $tmp = "tmp_" . ++$counter . ".txt"; open(TMP,">$tmp") || die $!; for(@buffer){ print TMP $_; } push(@tmp_files,$tmp); close(TMP); @buffer = (); } my @threads = (); for(@tmp_files){ push(@threads, new threads(\&sort_it,$_)); } $_->join for(@threads); my_print("Sorting completed, merging started\n"); #$thrs = scalar(@threads); #print "no of threads : $thrs\n"; #sleep(10); my @keys = keys %bounds; #my @vals = values %bounds; my $n_keys = scalar(@keys); my_print("no of keys : $n_keys\n"); #print "vals : @vals\n"; merge_it(\%bounds); my_print("merge completed\n"); my $tm2 = &my_time(); print "\n\n----------------Report ------------\n"; print "---------------- Sort Start : $tm1\n"; print "---------------- Sort End : $tm2\n"; print "-----------------------------------\n"; sub sort_it{ # my $ref = shift; # my $tmp = shift; my $chunk = shift; my $first = 1; my $tid = threads->self->tid(); my_print("thread $tid Sorting chunk : $chunk\n"); my @buf = (); open(TMP,"$chunk") || die $!; push (@buf, $_) while(<TMP>); close(TMP); open(TMP,">$chunk") || die $!; for(sort {my $fields1 = substr($a,10,10); my $fields2 = substr($b,10,10); $fields1 <=> $fields2 } @buf){ if($first){ { #lock lock(%bounds); $bounds{$chunk} = substr($_,10,10); } # unlock $first = 0; } print TMP $_; } close(TMP); # my @keys = keys %bounds; # print "keys : @keys\n"; my_print("thread $tid Sorting chunk : $chunk COMPLETED\n"); } sub merge_it{ my $ref = shift; my @files = sort {$ref->{$a} <=> $ref->{$b}} keys %{$ref}; my $merged_to = $files[0]; my_print("merging : $files[0]\n"); for(my $i=1; $i<@files; $i++){ open(FIRST,$merged_to) || dir $!; open(SECOND,$files[$i]) || dir $!; my_print ("merging : $files[$i]\n"); my $merged_tmp = "merged_tmp$i.txt"; open(MERGED,">$merged_tmp") || die $!; my $line1 = <FIRST>; my $line2 = <SECOND>; while(1){ if(!defined($line1) && defined($line2)){ print MERGED $line2; print MERGED while(<SECOND>); last; } if(!defined($line2) && defined($line1)){ print MERGED $line1; print MERGED while(<FIRST>); last; } last if(!defined($line1) && !defined($line2)); my $value1 = substr($line1,10,10); my $value2 = substr($line2,10,10); if($value1 == $value2){ print MERGED $line1; print MERGED $line2; $line1 = <FIRST>; $line2 = <SECOND>; }elsif($value1 > $value2){ while($value1 > $value2){ print MERGED $line2; $line2 = <SECOND>; last unless(defined $line2); $value2 = substr($line2,10,10); } }else{ while($value1 < $value2){ print MERGED $line1; $line1 = <FIRST>; last unless(defined $line1); $value1 = substr($line1,10,10); } } } close(FIRST); close(SECOND); close(MERGED); unlink $merged_to; unlink $files[$i]; $merged_to = $merged_tmp; } } sub my_print { my $cur_time = my_time(); print "$cur_time @_ "; } sub my_time() { my $time= time ; my $daytime = localtime($time) ; return $daytime ; } +++++++++++++++++++++++ __________________________________________________ Do you Yahoo!? Yahoo! Tax Center - forms, calculators, tips, more http://taxes.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]