Index: /issm/trunk/cron/run.sh
===================================================================
--- /issm/trunk/cron/run.sh	(revision 1933)
+++ /issm/trunk/cron/run.sh	(revision 1933)
@@ -0,0 +1,56 @@
+#!/bin/bash
+
+numprocs=8;
+
+#figure out if startup.m is here, otherwise, symlink it.
+if [ -e startup.m ]
+then
+	echo ""
+	#startup.m exists, do nothing
+else
+	echo "creating startup.m symlink file"
+	ln -s $ISSM_DIR/startup.m 
+fi
+
+
+for (( i=1;i<=$numprocs;i++ ))
+do
+
+	#Launch matlab and the nightly run script
+	cat > matlab_run$i.m << EOF
+	startup
+	warning off %necessary to avoid a nightly.log of several Go for cielo_parallel
+	try,
+		nightlyrun({'cielo_serial'},$i,$numprocs);
+	catch me,
+		%An error occured, get report and exit
+		message=getReport(me)
+		fid=fopen('matlaberror$i.log', 'wt');
+		fprintf(fid,'Matlab error occured in: %s\n',pwd);                                                                                                       
+		fprintf(fid,'%s',message);                                                                                                                              
+		fclose(fid);
+	end
+	exit
+EOF
+
+	matlab -nojvm -nosplash  -r matlab_run$i -logfile nightlylong$i.log &
+done
+
+wait
+
+#concatenate all reports
+mv nightlylong1.log  nightlylong.log
+for (( i=2;i<=$numprocs;i++ ))
+do
+	cat nightlylong.log nightlylong$i.log > nightlylong.log.bak
+	mv nightlylong.log.bak nightlylong.log
+	rm nightlylong$i.log
+
+done
+
+#remove unused lines to deal with a smaller file
+cat nightlylong.log | egrep 'difference: |NIGHTLYRUNTERMINATEDCORRECTLY' > nightly.log
+rm nightlylong.log
+
+#remove matlab_run scripts.
+rm -rf matlab_run*.m
Index: /issm/trunk/src/m/utils/Cluster/parallelrange.m
===================================================================
--- /issm/trunk/src/m/utils/Cluster/parallelrange.m	(revision 1933)
+++ /issm/trunk/src/m/utils/Cluster/parallelrange.m	(revision 1933)
@@ -0,0 +1,26 @@
+function [i1,i2]=parallelrange(rank,numprocs,globalsize)
+%PARALLELRANGE from a rank, and a number of processors, figure out a range, for parallel tasks.
+%
+% usage: [i1,i1]=parallelrange(rank,numprocs,globalsize)
+%
+
+
+num_local_rows=zeros(numprocs,1);
+
+for i=1:numprocs,
+
+	%we use floor. we under distribute rows. The rows left  are then redistributed, therefore resulting in a more even distribution.
+	num_local_rows(i)=floor(globalsize/numprocs);
+
+end
+
+
+%There may be some rows left. Distribute evenly.
+row_rest=globalsize - numprocs*floor(globalsize/numprocs);
+
+for i=1:row_rest,
+	num_local_rows(i)=num_local_rows(i)+1;
+end
+
+i1=sum(num_local_rows(1:rank-1))+1;
+i2=i1+num_local_rows(rank)-1;
Index: /issm/trunk/src/m/utils/Nightly/nightlyrun.m
===================================================================
--- /issm/trunk/src/m/utils/Nightly/nightlyrun.m	(revision 1932)
+++ /issm/trunk/src/m/utils/Nightly/nightlyrun.m	(revision 1933)
@@ -5,4 +5,6 @@
 %   launch the nightly tests. A specific package can be given in input
 %   only this package will be tested
+%   if last arguments are a pair of numbers, they represent the node rank and the number of 
+%   cpus being used for the nightly run.
 %
 %  Usage:
@@ -14,7 +16,8 @@
 %      nightlyrun({'cielo_serial','cielo_parallel'});
 %      nightlyrun({'ice'},{'prognostic','diagnostic'});
+%      nightlyrun({'ice'},{'prognostic','diagnostic'},1,3);
 
 %check arguments
-if (nargin>2)
+if (nargin>4)
 	help nightlyrun
 	error('nightlyrun error message: bad usage');
@@ -24,4 +27,16 @@
 global ISSM_DIR
 
+%recover rank and numprocs: 
+if nargin>=2,
+	rank=varargin{end-1};
+	numprocs=varargin{end};
+	if ~isnumeric(rank),
+		rank=1;
+	end
+	if ~isnumeric(numprocs),
+		numprocs=1;
+	end
+end
+
 %Go to Test directory
 eval(['cd ' ISSM_DIR '/test/']);
@@ -30,5 +45,5 @@
 cd Verification
 
-list=listfiles;
+list=listfilesparallel(rank,numprocs);
 
 %Get packages
Index: /issm/trunk/src/m/utils/OS/listfilesparallel.m
===================================================================
--- /issm/trunk/src/m/utils/OS/listfilesparallel.m	(revision 1933)
+++ /issm/trunk/src/m/utils/OS/listfilesparallel.m	(revision 1933)
@@ -0,0 +1,15 @@
+function list=listfilesparallel(rank,numprocs)
+%LISTFILESPARALLEL list files inside a directory, depending on rank  and number of processors running this routine.
+%        this is very OS dependent.
+%
+%   usage: list=listfilesparallel(rank,numprocs);
+%
+%
+%   see also LS DIR LISTFILES
+
+list=listfiles';
+numfiles=numel(list);
+
+%we now have a list, split it between all the processors.
+[i1,i2]=parallelrange(rank,numprocs,numfiles);
+list=list(i1:i2);
