From 20df90b86887c710e02129bddb500ac04cf0a3cd Mon Sep 17 00:00:00 2001
From: magnum <magnum>
Date: Fri, 7 Oct 2011 10:06:33 +0200
Subject: [PATCH 22/22] j7: Fix for huge figures in MPI sum/avg cps (64 bit overflow)

---
 src/status.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/status.c b/src/status.c
index 0133af1..3243e2d 100644
--- a/src/status.c
+++ b/src/status.c
@@ -222,7 +222,8 @@ static char *status_get_totalcps(char *buffer)
 	int use_ticks, bufcat = 0;
 	clock_t ticks;
 	unsigned long time, sumtime;
-	long long cps, crypts, sumcrypts;
+	unsigned long long cps;
+	double crypts, sumcrypts;
 	unsigned cps_100;
 
 	use_ticks = !status.crypts.hi && !status_restored_time;
@@ -238,7 +239,7 @@ static char *status_get_totalcps(char *buffer)
 	// This calculates the total cps figure (total crypts / avg run time).
 	// It will show optimistic if the nodes don't finish at the same time
 	MPI_Reduce(&time, &sumtime, 1, MPI_UNSIGNED_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
-	MPI_Reduce(&crypts, &sumcrypts, 1, MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD);
+	MPI_Reduce(&crypts, &sumcrypts, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
 	time = sumtime / mpi_p;
 	crypts = sumcrypts;
 
@@ -257,7 +258,7 @@ static char *status_get_totalcps(char *buffer)
 	if (cps >= 100)
 		bufcat = sprintf(buffer, "%llu", cps);
 	else {
-		cps_100 = (unsigned)((crypts * 100 / (time ? time : 1)) % 100);
+		cps_100 = (unsigned)((unsigned long long)(crypts * 100 / (time ? time : 1)) % 100);
 		bufcat = sprintf(buffer, "%llu.%02u", cps, cps_100);
 	}
 
@@ -275,7 +276,7 @@ static char *status_get_totalcps(char *buffer)
 	if (cps >= 100)
 		sprintf(&buffer[bufcat], " avg %llu", cps);
 	else {
-		cps_100 = (unsigned)((crypts * 100 / mpi_p / (time ? time : 1)) % 100);
+		cps_100 = (unsigned)((unsigned long long)(crypts * 100 / mpi_p / (time ? time : 1)) % 100);
 		sprintf(&buffer[bufcat], " avg%llu.%02u", cps, cps_100);
 	}
 	return buffer;
-- 
1.7.4.1

