Hello everybody, I have a problem, where I didn't find some solutions until now. I have a program for calculating. For it I must load large data (10GB). This files will be written in a structure. After that I call a function which calculate with this data and an input (load by a excel file). This funtion have 5 interlaced for-loops. The results are well and all runs fine but to get a result I must wait to 10 hours. I have found that I can do the calculates parallel with the Parallel::ForkManager, where the steps of the loop will be swap out at a extra core. The first tests was fine but the used RAM will be multiply by the number of cores. With the modules threads/threads::shared you can share hashes and arrays. For sharing the loaded data, i changed the structure to a hash. Unfortunately the calculating needs more than 24 hours so I canceled the programm. The same happens when I use onlny 2 cores. Now my question: it's there a possibility to share static variables (in the loops the data of the loaded data don't will be changem, I only reading from the structure). Or somebody have an other idea how I can release this problem? Thank you very much
my $maxProc=4; my $pm = new Parallel::ForkManager($maxProc); for(my $idy=0;$idy<=$#ySurf;$idy++) { my $currY = $ySurf[$idy]; for(my $alfaIdx=0;$alfaIdx<=$#alfas;$alfaIdx++) { $pm->start and next; my $alfa = $alfas[$alfaIdx]; my $norVectX = cos($alfa); my $norVectY = 0; my $norVectZ = sin($alfa); my $norTransf=TransfNorVec($input->{az}, $input->{el}, $norVec +tX, $norVectY, $norVectZ, $Side); my $intSurfx = $input->{MiddleX} - $input->{r}*$norVectX; my $intSurfy = $currY; my $intSurfz = ($input->{MiddleZ}+$input->{zOffset})-$input->{ +r}*$norVectZ; my $center = Divide($input->{w}, $input->{h}, $input->{M}, $in +put->{N}, $intSurfx, $intSurfy, $intSurfz, $alfa); my $surf=0; for(my $idx=0;$idx<$center->{count};$idx++) { my $xT = $center->{Px}[$idx]; my $yT = $center->{Py}[$idx]; my $zT = $center->{Pz}[$idx]; my $xTr = coordSystTransf($input->{az}, $input->{el}, $inp +ut->{MiddleX}, $input->{MiddleY}, $input->{MiddleZ}, $input->{ZeroX}, + $input->{ZeroY}, $input->{ZeroZ}, $xT, $yT, $zT, $Side); my $sqDiag = ($input->{w}/$input->{M})**2+($input->{h}/$in +put->{N})**2; my $P = new Points(); $P->{count}=0; for(my $dataIdx=0;$dataIdx<$data->{count};$dataIdx++) { my $inSphere = Check($sqDiag, $xTr->{xe}, $xTr->{ye}, +$xTr->{ze}, $data->{abs_x}[$dataIdx], $data->{abs_y}[$dataIdx], $data +->{abs_z}[$dataIdx]); if($inSphere == 1) { $P->{Px}[$P->{count}]=($data->{magX}[$dataIdx])*co +s($data->{phX}[$dataIdx]); $P->{Py}[$P->{count}]=($data->{magY}[$dataIdx])*co +s($data->{phY}[$dataIdx]); $P->{Pz}[$P->{count}]=($data->{magZ}[$dataIdx])*co +s($data->{phZ}[$dataIdx]); $P->{count}++; } } my $Poynt = new Trans(); if(defined($P->{Px}[0]) && defined($P->{Py}[0]) && defined +($P->{Pz}[0])) { $Poynt->{xe} = summe($P->{Px})/$P->{count}; $Poynt->{ye} = summe($P->{Py})/$P->{count}; $Poynt->{ze} = summe($P->{Pz})/$P->{count}; my $innerProd = $Poynt->{xe}*$norTransf->{xe}+$Poynt-> +{ye}*$norTransf->{ye}+$Poynt->{ze}*$norTransf->{ze}; $surf += ((($input->{w})/$input->{M})*(($input->{h})/$ +input->{N}))*$innerProd; } } print "\ny= ".$currY."; alfa= ".$alfa .";\n"; if($surf == 0) { print 1e-100 ."dB\n"; }else{ print sprintf("%.4f", 20*log(abs($surf))) ." dB\n"; } $pm->finish; } $pm->wait_all_children; }

In reply to Sharing statics variable between Threads by rodeo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.