wrote equivalent python code
This commit is contained in:
parent
3c8e68ac1d
commit
274622157a
16
src/main.cu
16
src/main.cu
|
|
@ -1,4 +1,4 @@
|
||||||
// #include "hurricanedata/fielddata.h"
|
#include "hurricanedata/fielddata.h"
|
||||||
#include "hurricanedata/gpubufferhandler.h"
|
#include "hurricanedata/gpubufferhandler.h"
|
||||||
#include "hurricanedata/datareader.h"
|
#include "hurricanedata/datareader.h"
|
||||||
#include "hurricanedata/gpubuffer.h"
|
#include "hurricanedata/gpubuffer.h"
|
||||||
|
|
@ -10,9 +10,10 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
__global__ void getSingleValue(float *ans, const FieldMetadata &fmd, FieldData fd) {
|
__global__ void middleOfTwoValues(float *ans, const FieldMetadata &fmd, FieldData fd) {
|
||||||
float xi = getVal(fmd, fd, 1, 20, 100, 100);
|
float xi = getVal(fmd, fd, 0, 20, 100, 100);
|
||||||
*ans = xi;
|
float yi = getVal(fmd, fd, 1, 20, 100, 100);
|
||||||
|
*ans = (xi+yi)/2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
@ -20,7 +21,6 @@ int main() {
|
||||||
|
|
||||||
std::string variable = "T";
|
std::string variable = "T";
|
||||||
|
|
||||||
// std::unique_ptr<DataReader> dataReader = std::make_unique<DataReader>(path, variable);
|
|
||||||
DataReader dataReader{path, variable};
|
DataReader dataReader{path, variable};
|
||||||
|
|
||||||
std::cout << "created datareader\n";
|
std::cout << "created datareader\n";
|
||||||
|
|
@ -38,16 +38,14 @@ int main() {
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
FieldData fd = bufferHandler.nextFieldData();
|
FieldData fd = bufferHandler.nextFieldData();
|
||||||
|
|
||||||
getSingleValue<<<1, 1>>>(ptr_test_read, *bufferHandler.fmd, fd);
|
middleOfTwoValues<<<1, 1>>>(ptr_test_read, *bufferHandler.fmd, fd);
|
||||||
|
|
||||||
cudaDeviceSynchronize();
|
cudaDeviceSynchronize();
|
||||||
|
|
||||||
std::cout << "ptr_test_read = " << std::fixed << std::setprecision(6) << *ptr_test_read << "\n";
|
std::cout << "ptr_test_read = " << std::fixed << std::setprecision(6) << *ptr_test_read << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Write an example loop using buffering and measure it.
|
// TODO: measure data transfer time in this example code.
|
||||||
|
|
||||||
// TODO: Free data properly in FieldData (maybe make an iterator)
|
|
||||||
cudaFree(ptr_test_read);
|
cudaFree(ptr_test_read);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
import numpy as np
|
||||||
|
from netCDF4 import Dataset
|
||||||
|
|
||||||
|
# file_path = 'data/MERRA2_400.inst6_3d_ana_Np.20120101.nc4'
|
||||||
|
# ncfile = Dataset(file_path, 'r')
|
||||||
|
|
||||||
|
file_paths = [
|
||||||
|
'data/atmosphere_MERRA-wind-speed[179253532]/MERRA2_400.inst6_3d_ana_Np.20120101.nc4',
|
||||||
|
'data/atmosphere_MERRA-wind-speed[179253532]/MERRA2_400.inst6_3d_ana_Np.20120102.nc4',
|
||||||
|
'data/atmosphere_MERRA-wind-speed[179253532]/MERRA2_400.inst6_3d_ana_Np.20120103.nc4'
|
||||||
|
]
|
||||||
|
|
||||||
|
ncfiles = [Dataset(file_path) for file_path in file_paths]
|
||||||
|
|
||||||
|
|
||||||
|
# print(f"{Temp[0, 20, 100, 100]=}")
|
||||||
|
|
||||||
|
for i in range(10):
|
||||||
|
Temp = ncfiles[i//4].variables['T'][:]
|
||||||
|
x = Temp[i%4, 20, 100, 100]
|
||||||
|
|
||||||
|
Temp2 = ncfiles[(i+1)//4].variables['T'][:]
|
||||||
|
y = Temp2[(i+1)%4, 20, 100, 100]
|
||||||
|
print(f"{(x+y)/2=}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Close the NetCDF file
|
||||||
|
for ncfile in ncfiles:
|
||||||
|
ncfile.close()
|
||||||
Loading…
Reference in New Issue