diff -u -r mrbayes-3.1.2.orig/bayes.c mrbayes-3.1.2.mod/bayes.c
--- mrbayes-3.1.2.orig/bayes.c	2005-12-24 01:26:28.000000000 +0900
+++ mrbayes-3.1.2.mod/bayes.c	2006-11-23 19:05:18.417875000 +0900
@@ -692,6 +692,7 @@
 	for (i=0; i<MAX_CHAINS; i++)
 		chainParams.userTemps[i] = 1.0;              /* user-defined chain temperatures               */
 	chainParams.swapAdjacentOnly = NO;               /* swap only adjacent temperatures               */
+	chainParams.swapDescendAll = NO;
 	chainParams.printMax = 8;						 /* maximum number of chains to print to screen   */
 	chainParams.printAll = YES;						 /* whether to print heated chains                */
 	chainParams.runWithData = YES;				     /* whether to run with data                      */
diff -u -r mrbayes-3.1.2.orig/command.c mrbayes-3.1.2.mod/command.c
--- mrbayes-3.1.2.orig/command.c	2005-12-24 01:53:30.000000000 +0900
+++ mrbayes-3.1.2.mod/command.c	2006-11-23 19:47:13.430750000 +0900
@@ -259,10 +259,10 @@
 			{ 25,            "Lset",  NO,            DoLset, 14,                                                     {28,29,30,31,32,33,34,40,51,52,53,91,92,131},        4,                "Sets the parameters of the likelihood model",  IN_CMD, SHOW },
 			{ 26,	       "Manual",  NO,          DoManual,  1,								    														{127},       36,				  "Prints a command reference to a text file",  IN_CMD, SHOW },
 			{ 27,          "Matrix", YES,          DoMatrix,  1,                                                                                             {11},112381728,                 "Defines matrix of characters in data block", IN_FILE, SHOW },
-			{ 28,            "Mcmc",  NO,            DoMcmc, 37,  {17,18,19,20,21,22,23,24,25,26,27,85,99,113,114,115,116,117,132,143,144,145,149,150,151,152,153,
-																														  154,155,156,157,158,159,160,161,167,170},    36,                   "Starts Markov chain Monte Carlo analysis",  IN_CMD, SHOW },
-			{ 29,           "Mcmcp",  NO,           DoMcmcp, 37,  {17,18,19,20,21,22,23,24,25,26,27,85,99,113,114,115,116,117,132,143,144,145,149,150,151,152,153,
-																														  154,155,156,157,158,159,160,161,167,170},        4, "Sets the parameters of a chain (without starting analysis)",  IN_CMD, SHOW },
+			{ 28,            "Mcmc",  NO,            DoMcmc, 39,  {17,18,19,20,21,22,23,24,25,26,27,85,99,113,114,115,116,117,132,133,143,144,145,149,150,151,152,153,
+																													  154,155,156,157,158,159,160,161,167,170,172},    36,                   "Starts Markov chain Monte Carlo analysis",  IN_CMD, SHOW },
+			{ 29,           "Mcmcp",  NO,           DoMcmcp, 39,  {17,18,19,20,21,22,23,24,25,26,27,85,99,113,114,115,116,117,132,133,143,144,145,149,150,151,152,153,
+																													  154,155,156,157,158,159,160,161,167,170,172},        4, "Sets the parameters of a chain (without starting analysis)",  IN_CMD, SHOW },
 			{ 30,        "Outgroup", YES,        DoOutgroup,  1,                                                                                             {79},    49152,                                     "Changes outgroup taxon",  IN_CMD, SHOW },
 			{ 31,           "Pairs", YES,           DoPairs,  1,                                                                                             {93},    32768,        "Defines nucleotide pairs (doublets) for stem models",  IN_CMD, SHOW },
 			{ 32,       "Partition",  NO,       DoPartition,  1,                                                                                             {16},        4,                              "Assigns a character partition",  IN_CMD, SHOW },
@@ -11810,6 +11810,7 @@
 	PARAM   (169, "Aarevmatpr",     DoPrsetParm,       "Dirichlet|Fixed|\0");
 	PARAM   (170, "Nswaps",         DoMcmcParm,       "\0");
 	PARAM   (171, "Autooverwrite",  DoSetParm,         "Yes|No|\0");
+	PARAM   (172, "Swapdescendall", DoMcmcParm,        "Yes|No|\0");
 	/* NOTE: If a change is made to the parameter table, make certain you
 	         change the number of elements (now 200) in paramTable[] (global.h: may not be necessary 
 	         and at the top of this file). */
diff -u -r mrbayes-3.1.2.orig/mb.h mrbayes-3.1.2.mod/mb.h
--- mrbayes-3.1.2.orig/mb.h	2005-12-24 01:26:28.000000000 +0900
+++ mrbayes-3.1.2.mod/mb.h	2006-11-23 19:06:44.886625000 +0900
@@ -780,6 +780,7 @@
 	int			pbfSampleTime;         /* how many cycles to calcualate site prob.      */
 	int			pbfSampleBurnin;       /* burnin period for each site for pseudo BF     */
 	int			swapAdjacentOnly;      /* whether we only swap adjacent temperatures    */
+	int			swapDescendAll;
 	int			redirect;              /* should output go to stdout                    */
 	int			allChains;             /* should stats be output for all chains?        */
 	int         numSwaps;              /* number of swaps to try each time              */
diff -u -r mrbayes-3.1.2.orig/mcmc.c mrbayes-3.1.2.mod/mcmc.c
--- mrbayes-3.1.2.orig/mcmc.c	2005-12-24 01:26:28.000000000 +0900
+++ mrbayes-3.1.2.mod/mcmc.c	2006-11-24 01:24:30.913750000 +0900
@@ -1534,15 +1534,25 @@
 	lnPriorB = curLnPr[swapB];
 
 	if (reweightingChars == YES)
+		{
 		lnR = (tempB * (lnLikeStateAonDataB + lnPriorA) + tempA * (lnLikeStateBonDataA + lnPriorB)) - (tempA * (lnLikeA + lnPriorA) + tempB * (lnLikeB + lnPriorB));
+		}
 	else
+		{
 		lnR = (tempB * (lnLikeA + lnPriorA) + tempA * (lnLikeB + lnPriorB)) - (tempA * (lnLikeA + lnPriorA) + tempB * (lnLikeB + lnPriorB));
+		}
 	if (lnR < -100.0)
+		{
 		r = 0.0;
+		}
 	else if (lnR > 0.0)
+		{
 		r =  1.0;
+		}
 	else
+		{
 		r =  exp (lnR);
+		}
 
 	isSwapSuccessful = NO;
 	if (RandomNumber(seed) < r)
@@ -1559,19 +1569,24 @@
 		isSwapSuccessful = YES;
 		}
 		
-	chI = chainId[swapA];
-	chJ = chainId[swapB];
-	if (chainId[swapB] < chainId[swapA])
+	if (swapA < swapB)
 		{
-		chI = chainId[swapB];
-		chJ = chainId[swapA];
+		chI = swapA;
+		chJ = swapB;
+		}
+	else
+		{
+		chI = swapB;
+		chJ = swapA;
 		}
 	runId = chI / chainParams.numChains;
 	chI = chI % chainParams.numChains;
 	chJ = chJ % chainParams.numChains;
 	swapInfo[runId][chJ][chI]++;
 	if (isSwapSuccessful == YES)
+		{
 		swapInfo[runId][chI][chJ]++;
+		}
 #	endif
 	
 	return (NO_ERROR);
@@ -8498,6 +8513,38 @@
 				return (ERROR);
 				}
 			}
+		/* set Swapdescendall */
+		else if (!strcmp(parmName, "Swapdescendall"))
+			{
+			if (expecting == Expecting(EQUALSIGN))
+				expecting = Expecting(ALPHA);
+			else if (expecting == Expecting(ALPHA))
+				{
+				if (IsArgValid(tkn, tempStr) == NO_ERROR)
+					{
+					if (!strcmp(tempStr, "Yes"))
+						chainParams.swapDescendAll = YES;
+					else
+						chainParams.swapDescendAll = NO;
+					}
+				else
+					{
+					MrBayesPrint ("%s   Invalid argument for Swapdescendall\n", spacer);
+					free(tempStr);
+					return (ERROR);
+					}
+				if (chainParams.swapDescendAll == YES)
+					MrBayesPrint ("%s   Setting program to attempt swaps descending order\n", spacer);
+				else
+					MrBayesPrint ("%s   Setting program to attempt all possible swaps between chains\n", spacer);
+				expecting = Expecting(PARAMETER) | Expecting(SEMICOLON);
+				}
+			else
+				{
+				free(tempStr);
+				return (ERROR);
+				}
+			}
 		else
 			{
 			free(tempStr);
@@ -10263,8 +10310,10 @@
 
 	int		chn;
 	
-	for (chn=0; chn<numLocalChains; chn++)
+	for (chn = 0; chn < numLocalChains; chn ++)
+		{
 		chainId[chn] = chn;
+		}
 
 #	endif
 		
@@ -11411,32 +11460,20 @@
 
 	int			i;
 	
-	/* this works for both the serial and parallel versions because the swapSeed is identical for all
-		processors, ensuring they all get the same sequence of chainIds to swap */
-#	if defined (MPI_ENABLED)
-
-	/* For now, we wonly allow random swaps in the MPI version. Other schemes require
-	   tagging of messages, or a dedicated server node doing message processing.      */
-	(*swapA) = (int) (RandomNumber(&swapSeed) * chainParams.numChains);
-	(*swapB) = (int) (RandomNumber(&swapSeed) * (chainParams.numChains - 1));
-	if ((*swapB) == (*swapA))
-		(*swapB) = chainParams.numChains - 1;
-
-#	else
-
-	if (chainParams.swapAdjacentOnly == NO)
+	if (chainParams.swapAdjacentOnly == YES)
 		{
-		(*swapA) = (int) (RandomNumber(&swapSeed) * chainParams.numChains);
-		(*swapB) = (int) (RandomNumber(&swapSeed) * (chainParams.numChains - 1));
-		if ((*swapB) == (*swapA))
-			(*swapB) = chainParams.numChains - 1;
+		(*swapA) = (int)(RandomNumber(&swapSeed) * (chainParams.numChains - 1));
+		(*swapB) = (*swapA) + 1;
 		}
 	else
 		{
-		(*swapA) = (int) (RandomNumber(&swapSeed) * (chainParams.numChains - 1));
-		(*swapB) = (*swapA) + 1;
+		(*swapA) = (int)(RandomNumber(&swapSeed) * chainParams.numChains);
+		(*swapB) = (int)(RandomNumber(&swapSeed) * chainParams.numChains);
+		while ((*swapA) == (*swapB))
+			{
+			(*swapB) = (int)(RandomNumber(&swapSeed) * chainParams.numChains);
+			}
 		}
-#   endif
 
 	i = run * chainParams.numChains;
 	(*swapA) += i;
@@ -33544,16 +33581,42 @@
 			{
 			for (i = 0; i<chainParams.numRuns; i++)
 				{
-				for (j = 0; j<chainParams.numSwaps; j++)
-				GetSwappers (&swapA, &swapB, i);
-				if (AttemptSwap (swapA, swapB, seed) == ERROR)
+				if (chainParams.swapDescendAll == YES)
 					{
-#					if defined (MPI_ENABLED)
-					nErrors++;
-#					else
-					MrBayesPrint ("%s   Unsuccessful swap of states\n", spacer);
-					return ERROR;
-#					endif
+					for (j = chainParams.numChains - 1; j > 0; j --)
+						{
+						swapA = (i * chainParams.numChains) + j;
+						swapB = swapA - 1;
+						if (AttemptSwap (swapA, swapB, seed) == ERROR)
+							{
+#							if defined (MPI_ENABLED)
+							nErrors++;
+#							else
+							MrBayesPrint ("%s   Unsuccessful swap of states\n", spacer);
+							return ERROR;
+#							endif
+							}
+						}
+					} 
+					else
+					{
+					for (j = 0; j<chainParams.numSwaps; j++)
+						{
+						GetSwappers (&swapA, &swapB, i);
+						while ((swapA / chainParams.numChains) != (swapB / chainParams.numChains))
+							{
+							GetSwappers (&swapA, &swapB, i);
+							}
+						if (AttemptSwap (swapA, swapB, seed) == ERROR)
+							{
+#							if defined (MPI_ENABLED)
+							nErrors++;
+#							else
+							MrBayesPrint ("%s   Unsuccessful swap of states\n", spacer);
+							return ERROR;
+#							endif
+							}
+						}
 					}
 				}
 			}
