File: PermuteVector.cpp

package info (click to toggle)
combblas 2.0.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 190,488 kB
  • sloc: cpp: 55,918; ansic: 25,134; sh: 3,691; makefile: 548; csh: 66; python: 49; perl: 21
file content (63 lines) | stat: -rw-r--r-- 1,320 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <mpi.h>
#include <sys/time.h> 
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
#include <sstream>
#include "../CombBLAS.h"

using namespace std;


int main(int argc, char* argv[])
{
	int nprocs, myrank;
	MPI_Init(&argc, &argv);
	MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
	MPI_Comm_rank(MPI_COMM_WORLD,&myrank);

	if(argc < 2)
	{
		if(myrank == 0)
		{
			cout << "Usage: ./PermuteVectors <VectorOne> <VectorTwo> ... (as many vectors as needed)\n" << endl;
			cout << "Permutes all the vector inputs with the same random order\n" << endl;
		}
		MPI_Finalize(); 
		return -1;
	}				
	{
		bool randpermed =  false;
		FullyDistVec<int,int> randperm;
		for(int i=1; i < argc; ++i)
		{ 
			string vecname(argv[i]);
			ifstream inputvec(vecname.c_str());

			if(myrank == 0)
			{	
				if(inputvec.fail())
				{
					cout << "One of the input vector files do not exist, aborting" << endl;
					MPI_Abort(MPI_COMM_WORLD, NOFILE);
					return -1;
				}
			}
			FullyDistVec<int,int> vec;
			vec.ReadDistribute(inputvec, 0);

			if(!randpermed)		
			{
				randperm.iota(vec.TotalLength(), 0);
				randperm.RandPerm();	// can't we seed this (to avoid indexing and iota generation?)
				randpermed = true;
			}
				
			inputvec.clear();
			inputvec.close();
		}
	}
	MPI_Finalize();
	return 0;
}