Skip to content

Commit

Permalink
Change Eigenvector files to binary format
Browse files Browse the repository at this point in the history
Data is all single precision and is same format as before (if newlines are not used)
  • Loading branch information
AlexGabourie committed Feb 10, 2021
1 parent b39f4c2 commit ed48271
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
15 changes: 9 additions & 6 deletions src/main_phonon/hessian.cu
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ void Hessian::find_eigenvectors(char* input_dir)
char file_eigenvectors[200];
strcpy(file_eigenvectors, input_dir);
strcat(file_eigenvectors, "/eigenvector.out");
FILE* fid_eigenvectors = my_fopen(file_eigenvectors, "w");
std::ofstream eigfile;
eigfile.open(file_eigenvectors, std::ios::out | std::ios::binary);

size_t dim = num_basis * 3;
std::vector<double> W(dim);
Expand All @@ -324,23 +325,25 @@ void Hessian::find_eigenvectors(char* input_dir)
double natural_to_THz = 1.0e6 / (TIME_UNIT_CONVERSION * TIME_UNIT_CONVERSION);

// output eigenvalues
float om2;
for (size_t n = 0; n < dim; n++) {
fprintf(fid_eigenvectors, "%g ", W[n] * natural_to_THz);
om2 = (float)(W[n] * natural_to_THz);
eigfile.write((char *)&om2, sizeof(float));
}
fprintf(fid_eigenvectors, "\n");

// output eigenvectors
float eig;
for (size_t col = 0; col < dim; col++) {
for (size_t a = 0; a < 3; a++) {
for (size_t b = 0; b < num_basis; b++) {
size_t row = a + b * 3;
// column-major order from cuSolver
fprintf(fid_eigenvectors, "%g ", eigenvectors[row + col * dim]);
eig = (float)eigenvectors[row + col * dim];
eigfile.write((char *)&eig, sizeof(float));
}
}
fprintf(fid_eigenvectors, "\n");
}
fclose(fid_eigenvectors);
eigfile.close();
}

void Hessian::parse_cutoff(char** param, size_t num_param)
Expand Down
2 changes: 2 additions & 0 deletions src/main_phonon/hessian.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "utilities/gpu_vector.cuh"
#include <stdio.h>
#include <vector>
#include <fstream>
#include <iostream>

class Box;
class Neighbor;
Expand Down
30 changes: 10 additions & 20 deletions src/measure/modal_analysis.cu
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,11 @@ void MODAL_ANALYSIS::setN(const std::vector<int>& cpu_type_size)

void MODAL_ANALYSIS::set_eigmode(int mode, std::ifstream& eigfile, GPU_Vector<float>& eig)
{
float floatval;
std::vector<float> floatval(num_participating);
eigfile.read((char *)(&floatval[0]), num_participating * sizeof(float));
for (int i = 0; i < num_participating; i++) {
eigfile >> floatval;
// column major ordering for cuBLAS
eig[mode + i * num_modes] = floatval;
eig[mode + i * num_modes] = floatval[i];
}
}

Expand Down Expand Up @@ -356,26 +356,20 @@ void MODAL_ANALYSIS::preprocess(
strcpy(eig_file_position, input_dir);
strcat(eig_file_position, "/eigenvector.in");
std::ifstream eigfile;
eigfile.open(eig_file_position);
eigfile.open(eig_file_position, std::ios::in | std::ios::binary);
if (!eigfile) {
PRINT_INPUT_ERROR("Cannot open eigenvector.in file.");
}

// GPU phonon code output format
std::string val;

// Setup binning
if (f_flag) {
GPU_Vector<double> f(num_modes, Memory_Type::managed);
getline(eigfile, val);
std::stringstream ss(val);
for (int i = 0; i < first_mode - 1; i++) {
ss >> f[0];
}
double temp;
eigfile.seekg((first_mode - 1) * sizeof(float));
float om2;
for (int i = 0; i < num_modes; i++) {
ss >> temp;
f[i] = copysign(sqrt(abs(temp)) / (2.0 * PI), temp);
eigfile.read((char *)(&om2), sizeof(float));
f[i] = copysign(sqrt(abs(om2)) / (2.0 * PI), om2);

}
double fmax, fmin; // freq are in ascending order in file
int shift;
Expand All @@ -398,18 +392,14 @@ void MODAL_ANALYSIS::preprocess(
if (num_modes % bin_size != 0) {
bin_count[num_bins - 1] = num_modes % bin_size;
}

getline(eigfile, val);
}

bin_sum.resize(num_bins, 0, Memory_Type::managed);
for (int i = 1; i < num_bins; i++)
bin_sum[i] = bin_sum[i - 1] + bin_count[i - 1];

// skips modes up to first_mode
for (int i = 1; i < first_mode; i++) {
getline(eigfile, val);
}
eigfile.seekg((3 * num_participating * first_mode) * sizeof(float));
for (int j = 0; j < num_modes; j++) // modes
{
set_eigmode(j, eigfile, eigx);
Expand Down

0 comments on commit ed48271

Please sign in to comment.