Schrift
Wiki:Tipp zum Debugging: use Data::Dumper; local $Data::Dumper::Useqq = 1; print Dumper \@var;
[thread]11191[/thread]

Arbeitsspeicherproblem in Perl lösen

Leser: 1


<< |< 1 2 >| >> 18 Einträge, 2 Seiten
soezkan
 2008-01-26 15:13
#105185 #105185
User since
2008-01-24
17 Artikel
BenutzerIn
[default_avatar]
Hallo alle zusammen,

Ich habe auch schon eine Antwort darauf von murphy
aus einem anderen Beitrag (Vielen Dank :)

murphy+2008-01-25 13:40:24--
Wenn der Stack überläuft, sollte man tendenziell als erstes die Rekursionstiefe der Algorithmen verringern bzw. die Funktionen so schreiben, dass man Tailcall-Elimination einsetzen kann.


Was ist eine Tailcall-Elimination? Ich bin leider kein Programmier-Crack ...

Hatte mein Perl-Script mit dem basic2pl-Modul von Basic ausrechnen lassen,
und versucht das in PHP umzuschreben (leider ohne Erfolg).
Das Script funktioniert einwandfrei, die Sache ist nur, dass es abbricht, wenn
es zu oft (>2000 mal) hintereinander aufgerufen wird (30 Sekunden lang).

Was tun? Kann mir da jemand einen Tipp geben?

Vielen Dank,
Soezkan

Hier der Source (Vielleicht kann da jemand was mit Anfangen:

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!"C:\apache\xampp\perl\bin\perl.exe"
#Translated from BASIC by basic2pl

##############################################################################
# Main program
#
my(%FORM); # Hash FORM wird initialisiert

foreach $pair (@ARGV) {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $FORM{$name} = $value;
}

@ARGV = ();
@Gosub_Stack = ();

$b5=$FORM{'lat'};
$l5=$FORM{'lon'};
$h=-$FORM{'tz'};
$y=$FORM{'year'};
$m=$FORM{'month'};
$d=$FORM{'day'};
L20:    push @Gosub_Stack, "AL20";
        goto L300;
AL20:   ;
; #     print "Enter your Latitude positive numbers North of equator, negative for South","\n";
; #     print "Longitude negative for West of Greenwich, positive for East","\n";
; #L30:    print "Lat, Long (deg)" . "? ";
; #        $input_tmp = <>;
; #        chomp($input_tmp);
; #        ($b5, $l5) = split(/\s*,\s*/, $input_tmp);
; #     print "enter your difference in time from Greenwich, positive numbers going East","\n";

; #L40:    print "Time zone (hrs)" . "? ";
; #        $input_tmp = <>;
; #        chomp($input_tmp);
; #        $h = $input_tmp;
L50:    $l5 = $l5/360;
        $z0 = $h/24;
L60:    push @Gosub_Stack, "AL60";
        goto L1170;
AL60:   ;
        $t = ($j-2451545)+$f;
L70:    $tt = $t/36525+1;
L80:    ; #               from 1900.0
L90:    push @Gosub_Stack, "AL90";
        goto L410;
AL90:   ;
        $t = $t+$z0;
L100:   ; # 
L110:   ; #        Get Sun's Position
L120:   push @Gosub_Stack, "AL120";
        goto L910;
AL120:  ;
        $a[1] = $a5;
        $d[1] = $d5;
L130:   $t = $t+1;
L140:   push @Gosub_Stack, "AL140";
        goto L910;
AL140:  ;
        $a[2] = $a5;
        $d[2] = $d5;
L150:   if ($a[2] < $a[1]) {
            $a[2] = $a[2]+$p2;
        }
L160:   $z1 = $dr*90.833;
        ; #  ' Zenith dist.
L170:   $s = sin($b5*$dr);
        $c = cos($b5*$dr);
L180:   $z = cos($z1);
        $m8 = 0;
        $w8 = 0;
        print("", "\n");
L190:   $a0 = $a[1];
        $d0 = $d[1];
L200:   $da = $a[2]-$a[1];
        $dd = $d[2]-$d[1];
L210:   $c0 = 0;
        $step_for_c0 = 1;
        $limit_for_c0 = 23;
        do {
L220:       $p = ($c0+1)/24;
L230:       $a2 = $a[1]+$p*$da;
            $d2 = $d[1]+$p*$dd;
L240:       push @Gosub_Stack, "AL240";
            goto L490;
AL240:      ;
L250:       $a0 = $a2;
            $d0 = $d2;
            $v0 = $v2;
L260:       $c0 += $step_for_c0;
        } until ($step_for_c0 > 0 ? $c0 > $limit_for_c0 : $c0 < $limit_for_c0);
L270:   push @Gosub_Stack, "AL270";
        goto L820;
AL270:  ;
        ; #  '  Special msg?
L280:   exit;
L290:   ; # 
L300:   ; #         Constants
L310:   ;
L320:   $p1 = 3.14159265;
        $p2 = 2*$p1;
L330:   $dr = $p1/180;
        $k1 = 15*$dr*1.0027379;
L340:   $s_str = "#1#";#Sunset
L350:   $r_str = "#2#";#Sunrise
L360:   $m1_str = "#3#";#No sunrise this date
L370:   $m2_str = "#4#";#No sunset this date
L380:   $m3_str = "#5#";#Sun down all day
L390:   $m4_str = "#6#";#Sun up all day
L400:   $Return_tmp = pop @Gosub_Stack;
        goto $Return_tmp;
L410:   ; #      LST at 0h zone time
L420:   $t0 = $t/36525;
L430:   $s = 24110.5+8640184.813*$t0;
L440:   $s = $s+86636.6*$z0+86400*$l5;
L450:   $s = $s/86400;
        $s = $s-int($s);
L460:   $t0 = $s*360*$dr;
L470:   $Return_tmp = pop @Gosub_Stack;
        goto $Return_tmp;
L480:   ; # 
L490:   ; #   Test an hour for an event
L500:   $l0 = $t0+$c0*$k1;
        $l2 = $l0+$k1;
L510:   $h0 = $l0-$a0;
        $h2 = $l2-$a2;
L520:   $h1 = ($h2+$h0)/2;
        ; #    Hour angle,
L530:   $d1 = ($d2+$d0)/2;
        ; #    declination,
L540:   ; #                 at half hour
L550:   if ($c0 > 0) {
            goto L570;
        }
L560:   $v0 = $s*sin($d0)+$c*cos($d0)*cos($h0)-$z;
L570:   $v2 = $s*sin($d2)+$c*cos($d2)*cos($h2)-$z;
L580:   if (sgn($v0) == sgn($v2)) {
            goto L800;
        }
L590:   $v1 = $s*sin($d1)+$c*cos($d1)*cos($h1)-$z;
L600:   $a = 2*$v2-4*$v1+2*$v0;
        $b = 4*$v1-3*$v0-$v2;
L610:   $d = $b*$b-4*$a*$v0;
        if ($d < 0) {
            goto L800;
        }
L620:   $d = sqrt($d);
L630:   if ($v0 < 0 && $v2 > 0) {
            print($r_str);
        }
L640:   if ($v0 < 0 && $v2 > 0) {
            $m8 = 1;
        }
L650:   if ($v0 > 0 && $v2 < 0) {
            print($s_str);
        }
L660:   if ($v0 > 0 && $v2 < 0) {
            $w8 = 1;
        }
L670:   $e = (-$b+$d)/(2*$a);
L680:   if ($e > 1 || $e < 0) {
            $e = (-$b-$d)/(2*$a);
        }
L690:   $t3 = $c0+$e+1/120;
        ; #   Round off
L700:   $h3 = int($t3);
        $m3 = int(($t3-$h3)*60);
L701:   ; #  PRINT USING "##:##";H3;M3;
$zeit = sprintf ("%02d:%02d|", $h3, $m3);
print($zeit);
L720:   $h7 = $h0+$e*($h2-$h0);
L730:   $n7 = -cos($d1)*sin($h7);
L740:   $d7 = $c*sin($d1)-$s*cos($d1)*cos($h7);
L750:   $az = atan2($n7,$d7)/$dr;
L760:   if ($d7 < 0) {
            $az = $az+180;
        }
L770:   if ($az < 0) {
            $az = $az+360;
        }
L780:   if ($az > 360) {
            $az = $az-360;
        }
L781:   ; #  PRINT USING ",  azimuth ###.#";AZ
; # L790:   print(",  azimuth ", $az,' ', "\n");
L790:   $azimuth=sprintf("%.3f", $az);

        print ($azimuth,"°|");
L800:   $Return_tmp = pop @Gosub_Stack;
        goto $Return_tmp;
L810:   ; # 
L820:   ; #    Special-message routine
L830:   if ($m8 == 0 && $w8 == 0) {
            goto L870;
        }
L840:   if ($m8 == 0) {
            print($m1_str, "\n");
        }
L850:   if ($w8 == 0) {
            print($m2_str, "\n");
        }
L860:   goto L890;
L870:   if ($v2 < 0) {
            print($m3_str, "\n");
        }
L880:   if ($v2 > 0) {
            print($m4_str, "\n");
        }
L890:   $Return_tmp = pop @Gosub_Stack;
        goto $Return_tmp;
L900:   ; # 
L910:   ; #    Fundamental arguments
L920:   ; #      (Van Flandern &amp;
L930:   ; #      Pulkkinen, 1979)
L940:   $l = 0.779072+0.00273790931*$t;
L950:   $g = 0.993126+0.0027377785*$t;
L960:   $l = $l-int($l);
        $g = $g-int($g);
L970:   $l = $l*$p2;
        $g = $g*$p2;
L980:   $v = 0.39785*sin($l);
L990:   $v = $v-0.01*sin($l-$g);
L1000:  $v = $v+0.00333*sin($l+$g);
L1010:  $v = $v-0.00021*$tt*sin($l);
L1020:  $u = 1-0.03349*cos($g);
L1030:  $u = $u-0.00014*cos(2*$l);
L1040:  $u = $u+8e-05*cos($l);
L1050:  $w = -0.0001-0.04129*sin(2*$l);
L1060:  $w = $w+0.03211*sin($g);
L1070:  $w = $w+0.00104*sin(2*$l-$g);
L1080:  $w = $w-0.00035*sin(2*$l+$g);
L1090:  $w = $w-8e-05*$tt*sin($g);
L1100:  ; # 
L1110:  ; #     Compute Sun's RA and Dec
L1120:  $s = $w/sqrt($u-$v*$v);
L1130:  $a5 = $l+atan2($s/sqrt(1-$s*$s),1);
L1140:  $s = $v/sqrt($u);
        $d5 = atan2($s/sqrt(1-$s*$s),1);
; # $r5 commented out, perl complains not used anywhere else ;
; # L1150:  $r5 = 1.00021*sqrt($u);
L1160:  $Return_tmp = pop @Gosub_Stack;
        goto $Return_tmp;
L1165:  ; # 
L1170:  ; #      Calendar --> JD
; #L1180:  print "Year, Month, Day" . "? ";
; #        $input_tmp = <>;
; #        chomp($input_tmp);
; #        ($y, $m, $d) = split(/\s*,\s*/, $input_tmp);
L1190:  $g = 1;
        if ($y < 1583) {
            $g = 0;
        }
L1200:  $d1 = int($d);
        $f = $d-$d1-0.5;
L1210:  $j = -int(7*(int(($m+9)/12)+$y)/4);
L1220:  if ($g == 0) {
            goto L1260;
            $s = sgn($m-9);

L1224:  $a = abs($m-9);
        }
L1230:  ; #  S=SGN M-9: A=ABS(M-9)
L1240:  $j3 = int($y+$s*int($a/7));
L1250:  $j3 = -int((int($j3/100)+1)*3/4);
L1260:  $j = $j+int(275*$m/9)+$d1+$g*$j3;
L1270:  $j = $j+1721027+2*$g+367*$y;
L1280:  if ($f >= 0) {
            goto L1300;
        }
L1290:  $f = $f+1;
        $j = $j-1;
L1300:  $Return_tmp = pop @Gosub_Stack;
        goto $Return_tmp;
L1310:  ; # 
L1320:  ; #    This program by Roger W. Sinnott calculates the times of sunrise
L1330:  ; #    and sunset on any date, accurate to the minute within several
L1340:  ; #    centuries of the present.  It correctly describes what happens in the 
L1350:  ; #    arctic and antarctic regions, where the Sun may not rise or set on
L1360:  ; #    a given date.  Enter north latitudes positive, west longitudes
L1370:  ; #    negative.  For the time zone, enter the number of hours west of
L1380:  ; #    Greenwich (e.g., 5 for EST, 4 for EDT).  The calculation is
L1390:  ; #    discussed in Sky &amp; Telescope for August 1994, page 84.
sub sgn
{
return $_[0] == 0 ? 0 : $_[0] < 0 ? -1 : 1;
}


----
Modedit Gwendragon:
Code-Tags für Perl-Code eingefügt
----
GwenDragon
 2008-01-26 15:52
#105186 #105186
User since
2005-01-17
14533 Artikel
Admin1
[Homepage]
user image
Hilfe, das ist so schlimm wie Fortran.

Ich würde es besser richtig umschreiben.
Kurz gefragt (habe den Code nicht genau alaysiert), was soll denn das Skript genau machen?
die Drachin, Gwendolyn


Unterschiedliche Perl-Versionen auf Windows (fast wie perlbrew) • Meine Perl-Artikel

soezkan
 2008-01-26 16:17
#105187 #105187
User since
2008-01-24
17 Artikel
BenutzerIn
[default_avatar]
Das Script berechnet den Sonnenauf- und -untergang für jeden beliebigen Ort auf der Erde.
Linuxer
 2008-01-26 16:36
#105188 #105188
User since
2006-01-27
3870 Artikel
HausmeisterIn

user image
Versteh ich das richtig, dass das von Basic nach Perl übersetzt wurde?
Wenn ja, dann poste doch bitte mal den Basic-Quelltext; den könnte man wahrscheinlich besser umschreiben als das, was da oben rausgekommen ist...
meine Beiträge: I.d.R. alle Angaben ohne Gewähr und auf Linux abgestimmt!
Die Sprache heisst Perl, nicht PERL. - Bitte Crossposts als solche kenntlich machen!
ptk
 2008-01-26 17:05
#105189 #105189
User since
2003-11-28
3645 Artikel
ModeratorIn
[default_avatar]
soezkan+2008-01-26 15:17:02--
Das Script berechnet den Sonnenauf- und -untergang für jeden beliebigen Ort auf der Erde.

Dazu gibt es ein fertiges Perl-Modul: CPAN:Astro::Sunrise
soezkan
 2008-01-26 18:58
#105200 #105200
User since
2008-01-24
17 Artikel
BenutzerIn
[default_avatar]
Super, genau sowas meinte ich! Hurra!
soezkan
 2008-01-27 11:34
#105227 #105227
User since
2008-01-24
17 Artikel
BenutzerIn
[default_avatar]
Ich habe jetzt statt meiner alten basic2perl errechneten Routione ein
CPAN-Modul integriert, dass ich aufrufe. Leider habe ich aber immer
noch das selbe Problem: nach einer bestimmten Anzahl von Aufrufen,
hängt sich Perl auf wegen zu hoher Speicherauslastung des Arbeitsspeichers
auf.

Was kann ich da bloss machen? Weiss da jemand einen Rat?
Gibt es keine Möglichkeit den Arbeitsspeicher wieder freizuschaufeln.
Deallocate? Oder sowas?

Herzlichen Dank für jeden Tipp,
Soezkan
renee
 2008-01-27 11:47
#105228 #105228
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Man sollte die Gültigkeitsbereiche von Variablen möglichst klein halten. Von daher wäre es ganz interessant zu sehen, wie Dein Programm im Moment aussieht.
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
soezkan
 2008-01-27 11:54
#105229 #105229
User since
2008-01-24
17 Artikel
BenutzerIn
[default_avatar]
Ich benutze einen Algorithmus von CPAN:
http://search.cpan.org/~syamal/Date-Indian-0.01/li...

Der rechnet mir auch die Auf- und Untergangszeiten vom Mond aus. Macht auch alles fein wie es soll, bloss eben nicht oft genug ;)
renee
 2008-01-27 12:00
#105230 #105230
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Und wie sieht Dein Programm aus, das das Modul einbindet?
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
<< |< 1 2 >| >> 18 Einträge, 2 Seiten



View all threads created 2008-01-26 15:13.