SHARE
TWEET

Untitled

a guest Oct 21st, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "Normalization.hpp"
  2. #include<limits>
  3. #include<iostream>
  4. #include "KNNRow.hpp"
  5.  
  6. using namespace std;
  7.  
  8. void Normalization::normalize(int argc, char *argv[]) {
  9.     int num_of_features = NUM_OF_FEATURES;
  10.     int i, j, numprocs, myid;
  11.     int  islave;
  12.  
  13.     MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
  14.     MPI_Comm_rank(MPI_COMM_WORLD, &myid);
  15.     MPI_Status status;
  16.  
  17.  
  18.     findMinMax(argc, argv);
  19.     vector<double> vector;
  20.  
  21.     double begin = MPI_Wtime();
  22.  
  23.     if (myid == 0) {
  24.             for (islave = 1; islave < numprocs; islave++) {
  25.                 MPI_Send(&inDataSize, 1, MPI_INTEGER, islave, MTAG1, MPI_COMM_WORLD);
  26.             }
  27.         } else {
  28.             MPI_Recv(&inDataSize, 1, MPI_INTEGER, 0, MTAG1, MPI_COMM_WORLD, &status);
  29.         }
  30.  
  31.  
  32.     for (i = myid; i < inDataSize; i+=numprocs) {
  33.         for (j = 0; j < num_of_features; j++) {
  34.             vector.push_back((inData[i].features[j] - min[j])
  35.                     / (max[j] - min[j]));
  36.         }
  37.     }
  38.  
  39.     double end = MPI_Wtime();
  40.     normalizationTime = end - begin;
  41.     normalizedData = inData;
  42. }
  43.  
  44. void Normalization::findMinMax(int argc, char *argv[]) {
  45.     int i, j;
  46.     int num_of_features = NUM_OF_FEATURES;
  47.     MPI_Status status;
  48.  
  49.     for( i=0;i<num_of_features;i++){
  50.         min[i]= numeric_limits<int>::max();
  51.     }
  52.  
  53.     int myid, numprocs, islave;
  54.     int world_rank;
  55.     MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
  56.     MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
  57.     double begin = MPI_Wtime();
  58.  
  59.     for ( i = world_rank; i < inDataSize; i+=numprocs) {
  60.         for (j = 0; j < num_of_features; j++) {
  61.             //printf("PRoces %d przetwarza dane inData[%d][%d] ktore jest rowne : %f\n", world_rank
  62.             //      , i, j, inData[i].features[j]);
  63.             if (min[j] > inData[i].features[j]) {
  64.                 min[j] = inData[i].features[j];
  65.             }
  66.  
  67.             if (max[j] < inData[i].features[j]) {
  68.                 max[j] = inData[i].features[j];
  69.             }
  70.         }
  71.     }
  72.  
  73.  
  74.  
  75.     double global_min[NUM_OF_FEATURES];
  76.     double global_max[NUM_OF_FEATURES];
  77.     for(int i = 0 ; i < NUM_OF_FEATURES; i++)
  78.     {
  79.         MPI_Reduce(&min[i], &global_min[i], 1, MPI_DOUBLE, MPI_MIN, 0,
  80.                          MPI_COMM_WORLD);
  81.         MPI_Reduce(&max[i], &global_max[i], 1, MPI_DOUBLE, MPI_MAX, 0,
  82.                                  MPI_COMM_WORLD);
  83.  
  84.  
  85.  
  86.         printf("Local min for process %d - %f \n",
  87.                  world_rank, min[i]);
  88.  
  89.         printf("Local max for process %d - %f \n",
  90.                  world_rank, max[i]);
  91.  
  92.         if (world_rank == 0) {
  93.                     printf("Total min = %f, max = %f\n\n", global_min[i],
  94.                            global_max[i] );
  95.                  }
  96.         MPI_Barrier(MPI_COMM_WORLD);
  97.     }
  98.     double end = MPI_Wtime();
  99.     minMaxTime = end - begin;
  100.     if (world_rank == 0) {
  101.         cout << numprocs;
  102.     }
  103. }
  104.  
  105. double Normalization::getNormalizationTime() {
  106.     return normalizationTime;
  107. }
  108.  
  109. double Normalization::getMinMaxTime(){
  110.     return minMaxTime;
  111. }
  112.  
  113. vector<Row> Normalization::getNormalizedData(){
  114.     return normalizedData;
  115.  
  116. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top