最近在处理一批数据,10的8次方,处理完毕大概要一个月,并且这个程序占用的CPU只有一个(我从来没有注意到这个问题啊啊啊)。
突然师兄提醒我可以把10的8次方条数据拆成10个10的7次方,作为10条任务并行处理,我艹,三天就跑完了啊,坑爹呢这是我之前怎么没想到呢混蛋!!
以后单任务的程序一定要注意下CPU的使用情况。
并行处理也有个简单的方法,就是把原始文件给切割后提交,让队列调度程序给你并行调度就ok了。大家不要拍砖啊,这个玩意儿还是挺有用处的。
下面这个破脚本,哦,是perl脚本,用来切割文件的。我这里讲某个文件切割成,每4000条数据一个文件,每1000个文件一个文件夹,闲话少说,上酸菜:
#!/usr/bin/perl -w # Program name: filter_pro.pl # Author : bbsunchen # Contact : bbsunchen at gm*il.com # Date : 11/10/2011 # Last Update : 11/10/2011 # Reference : Please cite our following papers when you are using this script. # Description : #=============================================================================================================== use warnings; use strict; use Getopt::Long; use Cwd qw(abs_path); use File::Basename qw(dirname); my %opts; GetOptions(\%opts,"dir:s"); my $usage= <<"USAGE"; Program: $0 INPUT: -dir full path of file OUTPUT: USAGE die $usage unless ($opts{dir} && -e $opts{dir}); my $cwd; if ($opts{dir} =~ m{^/}) { $cwd = dirname($opts{dir}); } else { $cwd = dirname(abs_path($opts{dir})); } open DIR, $opts{dir}; my $seq_num = 0; my $title = ""; my $data = ""; while(<DIR>) { $seq_num++; if($seq_num % 2 != 0) { $title = $_; next; }else { $data = $_; } my $decide_path = 0; if($seq_num % 2 == 0) { $decide_path = $seq_num / 2; }else { $decide_path = int($seq_num / 2) + 1; } my $file_name = int($decide_path / 4000); my $path_name = int($file_name / 1000); my $temp_path = "$cwd/$path_name"; mkdir $temp_path,0775 unless (-e "$temp_path"); die $! unless ($opts{dir} && -e $opts{dir}); open OUT, ">> $temp_path/$file_name.fa"; print OUT $title; print OUT $data; close OUT; } close DIR;