我有一個perl程序,它從pcap文件中讀取一個流的數據包,但它需要很長時間,我想使它平行,但我不知道它是可能的還是不是嗎?如果是的話,我可以用MPI來做嗎?另一個問題是讓代碼並行的最好方法,這裏是我的代碼片段(我認爲我應該在這部分中並行工作,但我不知道最好的辦法!)perl語言的並行執行
while (!eof($inFileH))
{
#inFileH is the handler of the pcap file
#in each while I read one packet
$ts_sec = readBytes($inFileH,4);
$ts_usec = readBytes($inFileH,4);
$incl_len = readBytes($inFileH,4);
$orig_len = readBytes($inFileH,4);
if ($totalLen == 0) # it is the 1st packet
{
$startTime = $ts_sec + $ts_usec/1000000;
}
$timeStamp = $ts_sec + $ts_usec/1000000 - $startTime;
$totalLen += $orig_len;
$#packet = -1; n # initing the array
for (my $i=0 ; $i<$incl_len ; $i++) #read all included octects of the current packet
{
read $inFileH, $packet[$i], 1;
$packet[$i] = ord($packet[$i]);
}
#and after that I will work on the "packet" and analyze it
所以我應該怎麼送其他處理器並行進行這項工作的文件內容.....
感謝您的完整解釋,但我認爲文件的大量是瓶頸,因爲當文件很小時執行時間減少,所以我決定用perl語言分割文件!你怎麼看?這是一個有效的解決方案嗎? – user3210586
可能不是。如果你可以細分文件,你可以走得更遠,甚至根本沒有提到腳本中的文件。不要將輸入視爲您首先需要讀取然後進行處理的文件,將其視爲可讀取並按塊處理塊的輸入數據流。這是在Perl中進行處理的標準方式 - 請參閱['''構造](http://stackoverflow.com/questions/189293/how-do-i-get-a-filehandle-from-the-command-line)。 – reinierpost
我已經把我的代碼放在上面了,正如你所說我使用了一個文件處理程序,但是我在分割流時遇到了一些問題!!我不知道什麼是有效的方法!!!你能幫我嗎? – user3210586