<commit_before>import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import ibis.util.PoolInfo;

class Slave extends UnicastRemoteObject implements SlaveInterface {

    static final double FORWARD = 1.0;
    static final double BACKWARD = -1.0;

    private int myCpu, cpus, N, M, rootN, rowsperproc;
    private double[] u, u2;
    private int[][] ind1, ind2;
    private MasterInterface master;
    private long transposeAndFFT, fftDuration, totalComDuration, barDuration;
    private Matrix[] matrixArray;
    private SlaveInterface[] slaveArray;
    private int[][] distribution;

//    public static native void fs_stats_reset();

    Slave(String masterName, int cpu, int cpus, int N, int M,
	  int rootN, int rowsperproc, double[] u, double[] u2,
	  int[][] dis, PoolInfo d) throws Exception {

	while (true) {
	    Thread.sleep(500);
	    try {
		master = (MasterInterface)Naming.lookup("//" + masterName + "/FFT_Master");
		System.out.println(cpu + ": Slave has found Master reference");
		break;
	    } catch (Exception e) {
		System.out.println(cpu + ": lookup master -- sleep a while...");
	    }
	}
	System.out.println("master is " + master);
	myCpu = cpu;
	this.cpus = cpus;
	this.N = N;
	this.M = M;
	this.rootN = rootN;
	this.rowsperproc = rowsperproc;
	this.u = u;
	this.u2 = u2;
	this.distribution = dis;
	transposeAndFFT = 0;
	fftDuration = 0;
	totalComDuration = 0;
	barDuration = 0;

	matrixArray = new Matrix[cpus];
	for (int i = 0; i < cpus; i++) {
	    matrixArray[i] = new Matrix(rowsperproc);
	}
	slaveArray = master.table((SlaveInterface) this, myCpu);

	if (cpus > 1) master.sync();

	int myFirst = rootN * myCpu / cpus;
	int myLast = rootN * (myCpu + 1) / cpus;
	ind1 = new int[cpus][cpus];
	ind2 = new int[cpus][cpus];
	initIndexBlocks(ind1, ind2);
	initX(ind1, myFirst);

	if (cpus > 1) master.sync();

	long start = System.currentTimeMillis();

	double checksum1 = checksum();

	doFFT(FORWARD,  u, u2, myFirst, myLast);
	double checksum3 = checksum();
	doFFT(BACKWARD, u, u2, myFirst, myLast);
	double checksum2 = checksum();

	if (cpus > 1) master.sync();

	long end = System.currentTimeMillis();

	if (Math.abs(checksum1 - checksum2) > 0.1) {
		System.out.println("CPU" + myCpu + " checksum ERROR !!! (" +
				   checksum1 + "," + checksum2 + ")   " + checksum3);
	} else {
//		System.out.println("CPU" + myCpu + " checksum OK (" + 
//				   checksum1+","+checksum2+")   " + checksum3);
	
//		System.out.println(myCpu + "-> FFT: " + fftDuration + "\t Trans: " +
//				   transposeAndFFT + "\t Communication: " +
//				   totalComDuration + "\t Barriers: " + barDuration +
//				   " ms.\t     ");
	}

	if (myCpu == 0) { 
		System.out.println("FFT, M = " + M + " time " + ((end-start)/1000.0));
	}
	//d.printTime("FFT, M = " + M, transposeAndFFT);
    }


    void initIndexBlocks(int[][] ind1, int[][] ind2) {
	for (int i = 0; i < cpus; i++)
	    for (int j = 0; j < cpus; j++) {
		ind1[i][j] = i * cpus + j;
		ind2[j][i] = i * cpus + j;
	    }
    }


    void initX(int[][] ind, int myFirst) {
	double[] matrix = new double[rowsperproc * rootN * 2];

	for (int i = 0; i < rootN; i++)
	    for (int j = 0; j < rowsperproc; j++) {
		int index = 2 * (i + j * rootN);
		double value = myFirst + j + i * rootN + 0.1;
		matrix[index] = value;
		matrix[index + 1] = value + 1000.0;
	    }

	pageOut(matrix, ind);
    }


    void pageOut(double[] x, int[][] ind) {
	try {
//	    long start = System.currentTimeMillis();
//	    double[] matrix = master.getMatrixValues(ind[myCpu][0]);
	    int slaveNr = distribution[0][ ind[myCpu][0] ];
	    int matrixNr =distribution[0][ ind[myCpu][0] ];

//          PERFORMANCE BUG ??? 
//
//	    double[] matrix;

//	    if (myCpu == slaveNr) {
//		matrix = getCopyValues(matrixNr);
//	    } else { 
//		    matrix = slaveArray[slaveNr].getValues(matrixNr);
//	    } 
//
//    
	    double [] matrix = new double[rowsperproc*rowsperproc*2];

	    for (int i = 0; i < rootN; i++) {
		for (int j = 0; j < rowsperproc; j++) {
		    int index = ((i % rowsperproc) + j * rowsperproc) * 2;
		    matrix[index] = x[(i + rootN * j) * 2];
		    matrix[index + 1] =  x[(i + rootN * j) * 2 + 1];
		}
		if (i % rowsperproc == (rowsperproc - 1)) {
//		    master.setMatrixValues(ind[myCpu][i / rowsperproc], matrix);
		    slaveNr = distribution[0][ ind[myCpu][i / rowsperproc] ];
		    matrixNr =distribution[1][ ind[myCpu][i / rowsperproc] ];
		    if (slaveNr == myCpu) {
			setCopyValues(matrixNr, matrix);
//			System.out.println(slaveNr + "Exchange got matrix " + matrixNr + " " + matrix[0]); 
		    } else { 
			  slaveArray[slaveNr].setValues(matrixNr, matrix);
		    }
		    
		}<commit_msg>Reduce prints to 1 line wrt Master<commit_after>import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import ibis.util.PoolInfo;

class Slave extends UnicastRemoteObject implements SlaveInterface {

    static final double FORWARD = 1.0;
    static final double BACKWARD = -1.0;

    private int myCpu, cpus, N, M, rootN, rowsperproc;
    private double[] u, u2;
    private int[][] ind1, ind2;
    private MasterInterface master;
    private long transposeAndFFT, fftDuration, totalComDuration, barDuration;
    private Matrix[] matrixArray;
    private SlaveInterface[] slaveArray;
    private int[][] distribution;

//    public static native void fs_stats_reset();

    Slave(String masterName, int cpu, int cpus, int N, int M,
	  int rootN, int rowsperproc, double[] u, double[] u2,
	  int[][] dis, PoolInfo d) throws Exception {

	while (true) {
	    Thread.sleep(500);
	    try {
		master = (MasterInterface)Naming.lookup("//" + masterName + "/FFT_Master");
		System.out.println(cpu + ": Slave has found Master " + master);
		break;
	    } catch (Exception e) {
		System.out.println(cpu + ": lookup master -- sleep a while...");
	    }
	}
	myCpu = cpu;
	this.cpus = cpus;
	this.N = N;
	this.M = M;
	this.rootN = rootN;
	this.rowsperproc = rowsperproc;
	this.u = u;
	this.u2 = u2;
	this.distribution = dis;
	transposeAndFFT = 0;
	fftDuration = 0;
	totalComDuration = 0;
	barDuration = 0;

	matrixArray = new Matrix[cpus];
	for (int i = 0; i < cpus; i++) {
	    matrixArray[i] = new Matrix(rowsperproc);
	}
	slaveArray = master.table((SlaveInterface) this, myCpu);

	// System.err.println(myCpu + ": gonna hit barrier I");

	if (cpus > 1) master.sync();

	// System.err.println(myCpu + ": past barrier I");

	int myFirst = rootN * myCpu / cpus;
	int myLast = rootN * (myCpu + 1) / cpus;
	ind1 = new int[cpus][cpus];
	ind2 = new int[cpus][cpus];
	initIndexBlocks(ind1, ind2);
	// System.err.println(myCpu + ": Past initIndexBlocks");
	initX(ind1, myFirst);

	// System.err.println(myCpu + ": gonna hit barrier II");

	if (cpus > 1) master.sync();

	// System.err.println(myCpu + ": past barrier II, start clock");

	long start = System.currentTimeMillis();

	double checksum1 = checksum();

	doFFT(FORWARD,  u, u2, myFirst, myLast);
	double checksum3 = checksum();
	doFFT(BACKWARD, u, u2, myFirst, myLast);
	double checksum2 = checksum();

	if (cpus > 1) master.sync();

	long end = System.currentTimeMillis();

	if (Math.abs(checksum1 - checksum2) > 0.1) {
		System.out.println("CPU" + myCpu + " checksum ERROR !!! (" +
				   checksum1 + "," + checksum2 + ")   " + checksum3);
	} else {
//		System.out.println("CPU" + myCpu + " checksum OK (" + 
//				   checksum1+","+checksum2+")   " + checksum3);
	
//		System.out.println(myCpu + "-> FFT: " + fftDuration + "\t Trans: " +
//				   transposeAndFFT + "\t Communication: " +
//				   totalComDuration + "\t Barriers: " + barDuration +
//				   " ms.\t     ");
	}

	if (myCpu == 0) { 
		System.out.println("FFT, M = " + M + " time " + ((end-start)/1000.0));
	}
	//d.printTime("FFT, M = " + M, transposeAndFFT);
    }


    void initIndexBlocks(int[][] ind1, int[][] ind2) {
	for (int i = 0; i < cpus; i++)
	    for (int j = 0; j < cpus; j++) {
		ind1[i][j] = i * cpus + j;
		ind2[j][i] = i * cpus + j;
	    }
    }


    void initX(int[][] ind, int myFirst) {
	double[] matrix = new double[rowsperproc * rootN * 2];

	for (int i = 0; i < rootN; i++)
	    for (int j = 0; j < rowsperproc; j++) {
		int index = 2 * (i + j * rootN);
		double value = myFirst + j + i * rootN + 0.1;
		matrix[index] = value;
		matrix[index + 1] = value + 1000.0;
	    }

	pageOut(matrix, ind);
    }


    void pageOut(double[] x, int[][] ind) {
	try {
//	    long start = System.currentTimeMillis();
//	    double[] matrix = master.getMatrixValues(ind[myCpu][0]);
	    int slaveNr = distribution[0][ ind[myCpu][0] ];
	    int matrixNr =distribution[0][ ind[myCpu][0] ];

//          PERFORMANCE BUG ??? 
//
//	    double[] matrix;

//	    if (myCpu == slaveNr) {
//		matrix = getCopyValues(matrixNr);
//	    } else { 
//		    matrix = slaveArray[slaveNr].getValues(matrixNr);
//	    } 
//
//    
	    double [] matrix = new double[rowsperproc*rowsperproc*2];

	    for (int i = 0; i < rootN; i++) {
		for (int j = 0; j < rowsperproc; j++) {
		    int index = ((i % rowsperproc) + j * rowsperproc) * 2;
		    matrix[index] = x[(i + rootN * j) * 2];
		    matrix[index + 1] =  x[(i + rootN * j) * 2 + 1];
		}
		if (i % rowsperproc == (rowsperproc - 1)) {
//		    master.setMatrixValues(ind[myCpu][i / rowsperproc], matrix);
		    slaveNr = distribution[0][ ind[myCpu][i / rowsperproc] ];
		    matrixNr =distribution[1][ ind[myCpu][i / rowsperproc] ];
		    if (slaveNr == myCpu) {
			// System.err.print("=" + slaveNr);
			setCopyValues(matrixNr, matrix);
			// System.err.print(">");
//			System.out.println(slaveNr + "Exchange got matrix " + matrixNr + " " + matrix[0]); 
		    } else { 
			// System.err.print("<" + slaveNr);
			  slaveArray[slaveNr].setValues(matrixNr, matrix);
			// System.err.print(">");
		    }
		    
		}
{'fraction_non_alphanumeric': 0.17030167142274766, 'fraction_numerical': 0.017019975540154914, 'mean_word_length': 2.9158020750199523, 'pattern_counts': {'":': 9, '<': 18, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '81114', 'n_tokens_mistral': 3966, 'n_tokens_neox': 3666, 'n_words': 894}