Use socket block read/write for geometry data

This commit is contained in:
Magne Sjaastad
2014-04-03 10:41:27 +02:00
parent 0bdacfba17
commit acc1d732d7
5 changed files with 89 additions and 170 deletions

View File

@@ -87,11 +87,14 @@ public:
// dv(2) = cellCountK; // dv(2) = cellCountK;
// dv(3) = 3; // dv(3) = 3;
std::vector<double> cellCenterValues(doubleValueCount);
cvf::Vec3d cornerVerts[8]; cvf::Vec3d cornerVerts[8];
quint64 coordCount = 0; size_t blockByteCount = cellCount * sizeof(double);
std::vector<double> doubleValues(blockByteCount);
for (int coordIdx = 0; coordIdx < 3; coordIdx++) for (int coordIdx = 0; coordIdx < 3; coordIdx++)
{ {
quint64 valueIndex = 0;
for (size_t k = 0; k < cellCountK; k++) for (size_t k = 0; k < cellCountK; k++)
{ {
for (size_t j = 0; j < cellCountJ; j++) for (size_t j = 0; j < cellCountJ; j++)
@@ -101,15 +104,15 @@ public:
size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k);
cvf::Vec3d center = rigGrid->cell(localCellIdx).center(); cvf::Vec3d center = rigGrid->cell(localCellIdx).center();
cellCenterValues[coordCount++] = center[coordIdx]; doubleValues[valueIndex++] = center[coordIdx];
}
} }
} }
} }
CVF_ASSERT(coordCount == doubleValueCount); CVF_ASSERT(valueIndex == cellCount);
RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCenterValues.data(), byteCount); RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)doubleValues.data(), blockByteCount);
}
return true; return true;
} }
@@ -152,6 +155,11 @@ public:
size_t activeCellCount = actCellInfo->globalActiveCellCount(); size_t activeCellCount = actCellInfo->globalActiveCellCount();
size_t doubleValueCount = activeCellCount * 3; size_t doubleValueCount = activeCellCount * 3;
socketStream << (quint64)activeCellCount;
quint64 byteCount = doubleValueCount * sizeof(double);
socketStream << byteCount;
// This structure is supposed to be received by Octave using a NDArray. The ordering of this loop is // This structure is supposed to be received by Octave using a NDArray. The ordering of this loop is
// defined by the ordering of the receiving NDArray // defined by the ordering of the receiving NDArray
// //
@@ -162,27 +170,25 @@ public:
// dv(0) = coordCount; // dv(0) = coordCount;
// dv(1) = 3; // dv(1) = 3;
std::vector<double> cellCenterValues(doubleValueCount); size_t blockByteCount = activeCellCount * sizeof(double);
quint64 coordCount = 0; std::vector<double> doubleValues(blockByteCount);
for (int coordIdx = 0; coordIdx < 3; coordIdx++) for (int coordIdx = 0; coordIdx < 3; coordIdx++)
{ {
quint64 valueIndex = 0;
for (size_t globalCellIdx = 0; globalCellIdx < mainGrid->cells().size(); globalCellIdx++) for (size_t globalCellIdx = 0; globalCellIdx < mainGrid->cells().size(); globalCellIdx++)
{ {
if (!actCellInfo->isActive(globalCellIdx)) continue; if (!actCellInfo->isActive(globalCellIdx)) continue;
cvf::Vec3d center = mainGrid->cells()[globalCellIdx].center(); cvf::Vec3d center = mainGrid->cells()[globalCellIdx].center();
cellCenterValues[coordCount++] = center[coordIdx]; doubleValues[valueIndex++] = center[coordIdx];
}
} }
CVF_ASSERT(coordCount == doubleValueCount); CVF_ASSERT(valueIndex == activeCellCount);
RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)doubleValues.data(), blockByteCount);
socketStream << (quint64)activeCellCount; }
quint64 byteCount = doubleValueCount * sizeof(double);
socketStream << byteCount;
RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCenterValues.data(), byteCount);
return true; return true;
} }
@@ -244,17 +250,18 @@ public:
// dv(3) = 8; // dv(3) = 8;
// dv(4) = 3; // dv(4) = 3;
cvf::Timer timer;
if (RiaApplication::instance()->preferences()->useStreamTransfer())
{
cvf::Vec3d cornerVerts[8]; cvf::Vec3d cornerVerts[8];
size_t blockByteCount = cellCount * sizeof(double);
std::vector<double> doubleValues(blockByteCount);
for (int coordIdx = 0; coordIdx < 3; coordIdx++) for (int coordIdx = 0; coordIdx < 3; coordIdx++)
{ {
for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++)
{ {
size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx];
quint64 valueIndex = 0;
for (size_t k = 0; k < cellCountK; k++) for (size_t k = 0; k < cellCountK; k++)
{ {
for (size_t j = 0; j < cellCountJ; j++) for (size_t j = 0; j < cellCountJ; j++)
@@ -264,47 +271,16 @@ public:
size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k);
rigGrid->cellCornerVertices(localCellIdx, cornerVerts); rigGrid->cellCornerVertices(localCellIdx, cornerVerts);
socketStream << cornerVerts[cornerIndexMapping][coordIdx]; doubleValues[valueIndex++] = cornerVerts[cornerIndexMapping][coordIdx];
}
}
}
}
}
}
else
{
std::vector<double> cellCornerValues(doubleValueCount);
cvf::Vec3d cornerVerts[8];
quint64 coordCount = 0;
for (int coordIdx = 0; coordIdx < 3; coordIdx++)
{
for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++)
{
size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx];
for (size_t k = 0; k < cellCountK; k++)
{
for (size_t j = 0; j < cellCountJ; j++)
{
for (size_t i = 0; i < cellCountI; i++)
{
size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k);
rigGrid->cellCornerVertices(localCellIdx, cornerVerts);
cellCornerValues[coordCount++] = cornerVerts[cornerIndexMapping][coordIdx];
}
}
} }
} }
} }
RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCornerValues.data(), byteCount); CVF_ASSERT(valueIndex, cellCount);
RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)doubleValues.data(), blockByteCount);
}
} }
double totalTimeMS = timer.time() * 1000.0;
QString resultInfo = QString("Total time '%1 ms'").arg(totalTimeMS);
server->errorMessageDialog()->showMessage(resultInfo);
return true; return true;
} }
@@ -348,6 +324,10 @@ public:
size_t activeCellCount = actCellInfo->globalActiveCellCount(); size_t activeCellCount = actCellInfo->globalActiveCellCount();
size_t doubleValueCount = activeCellCount * 3 * 8; size_t doubleValueCount = activeCellCount * 3 * 8;
socketStream << (quint64)activeCellCount;
quint64 byteCount = doubleValueCount * sizeof(double);
socketStream << byteCount;
// This structure is supposed to be received by Octave using a NDArray. The ordering of this loop is // This structure is supposed to be received by Octave using a NDArray. The ordering of this loop is
// defined by the ordering of the receiving NDArray // defined by the ordering of the receiving NDArray
// //
@@ -359,31 +339,32 @@ public:
// dv(1) = 8; // dv(1) = 8;
// dv(2) = 3; // dv(2) = 3;
std::vector<double> cellCornerValues(doubleValueCount);
cvf::Vec3d cornerVerts[8]; cvf::Vec3d cornerVerts[8];
quint64 coordCount = 0; size_t blockByteCount = activeCellCount * sizeof(double);
std::vector<double> doubleValues(blockByteCount);
for (int coordIdx = 0; coordIdx < 3; coordIdx++) for (int coordIdx = 0; coordIdx < 3; coordIdx++)
{ {
for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++)
{ {
size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx];
quint64 valueIndex = 0;
for (size_t globalCellIdx = 0; globalCellIdx < mainGrid->cells().size(); globalCellIdx++) for (size_t globalCellIdx = 0; globalCellIdx < mainGrid->cells().size(); globalCellIdx++)
{ {
if (!actCellInfo->isActive(globalCellIdx)) continue; if (!actCellInfo->isActive(globalCellIdx)) continue;
mainGrid->cellCornerVertices(globalCellIdx, cornerVerts); mainGrid->cellCornerVertices(globalCellIdx, cornerVerts);
cellCornerValues[coordCount++] = cornerVerts[cornerIndexMapping][coordIdx]; doubleValues[valueIndex++] = cornerVerts[cornerIndexMapping][coordIdx];
}
}
} }
socketStream << (quint64)activeCellCount; CVF_ASSERT(valueIndex == activeCellCount);
quint64 byteCount = doubleValueCount * sizeof(double);
socketStream << byteCount;
RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCornerValues.data(), byteCount); RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)doubleValues.data(), blockByteCount);
}
}
return true; return true;
} }

View File

@@ -1,7 +1,10 @@
#include <QtNetwork> #include <QtNetwork>
#include <QStringList>
#include <octave/oct.h> #include <octave/oct.h>
#include "riSettings.h" #include "riSettings.h"
#include "riSocketTools.h"
void getActiveCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16 port, const qint32& caseId, const QString& porosityModel) void getActiveCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16 port, const qint32& caseId, const QString& porosityModel)
@@ -61,24 +64,16 @@ void getActiveCellCenters(NDArray& cellCenterValues, const QString &hostName, qu
cellCenterValues.resize(dv); cellCenterValues.resize(dv);
while (socket.bytesAvailable() < (qint64)(byteCount))
{
if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs))
{
error((("Waiting for data: ") + socket.errorString()).toLatin1().data());
return;
}
OCTAVE_QUIT;
}
quint64 bytesRead = 0;
double* internalMatrixData = cellCenterValues.fortran_vec(); double* internalMatrixData = cellCenterValues.fortran_vec();
bytesRead = socket.read((char*)(internalMatrixData), byteCount); QStringList errorMessages;
if (!readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages))
if (byteCount != bytesRead)
{ {
error("Could not read binary double data properly from socket"); for (int i = 0; i < errorMessages.size(); i++)
octave_stdout << "Active cell count: " << activeCellCount << std::endl; {
error(errorMessages[i].toLatin1().data());
}
OCTAVE_QUIT;
} }
return; return;

View File

@@ -1,7 +1,10 @@
#include <QtNetwork> #include <QtNetwork>
#include <QStringList>
#include <octave/oct.h> #include <octave/oct.h>
#include "riSettings.h" #include "riSettings.h"
#include "riSocketTools.h"
void getActiveCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 port, const qint32& caseId, const QString& porosityModel) void getActiveCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 port, const qint32& caseId, const QString& porosityModel)
@@ -61,24 +64,16 @@ void getActiveCellCorners(NDArray& cellCornerValues, const QString &hostName, qu
dv(2) = 3; dv(2) = 3;
cellCornerValues.resize(dv); cellCornerValues.resize(dv);
while (socket.bytesAvailable() < (qint64)(byteCount))
{
if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs))
{
error((("Waiting for data: ") + socket.errorString()).toLatin1().data());
return;
}
OCTAVE_QUIT;
}
quint64 bytesRead = 0;
double* internalMatrixData = cellCornerValues.fortran_vec(); double* internalMatrixData = cellCornerValues.fortran_vec();
bytesRead = socket.read((char*)(internalMatrixData), byteCount); QStringList errorMessages;
if (!readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages))
if (byteCount != bytesRead)
{ {
error("Could not read binary double data properly from socket"); for (int i = 0; i < errorMessages.size(); i++)
octave_stdout << "Active cell count: " << activeCellCount << std::endl; {
error(errorMessages[i].toLatin1().data());
}
OCTAVE_QUIT;
} }
return; return;

View File

@@ -1,7 +1,10 @@
#include <QtNetwork> #include <QtNetwork>
#include <QStringList>
#include <octave/oct.h> #include <octave/oct.h>
#include "riSettings.h" #include "riSettings.h"
#include "riSocketTools.h"
void getCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16 port, const qint32& caseId, const quint32& gridIndex) void getCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16 port, const qint32& caseId, const quint32& gridIndex)
@@ -66,39 +69,19 @@ void getCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16
dv(3) = 3; dv(3) = 3;
cellCenterValues.resize(dv); cellCenterValues.resize(dv);
while (socket.bytesAvailable() < (qint64)(byteCount))
double* internalMatrixData = cellCenterValues.fortran_vec();
QStringList errorMessages;
if (!readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages))
{ {
if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) for (int i = 0; i < errorMessages.size(); i++)
{ {
error((("Waiting for data: ") + socket.errorString()).toLatin1().data()); error(errorMessages[i].toLatin1().data());
return;
} }
OCTAVE_QUIT; OCTAVE_QUIT;
} }
//octave_stdout << " riGetCellCenters : I = " << cellCountI <<" J = " << cellCountJ << " K = " << cellCountK << std::endl;
//octave_stdout << " riGetCellCenters : numDoubles = " << valueCount << std::endl;
double* internalMatrixData = cellCenterValues.fortran_vec();
#if 0
octave_idx_type valueCount = cellCenterValues.length();
double val;
for (octave_idx_type i = 0; i < valueCount; i++)
{
socketStream >> internalMatrixData[i];
}
#else
quint64 bytesRead = 0;
bytesRead = socket.read((char*)(internalMatrixData), byteCount);
if (byteCount != bytesRead)
{
error("Could not read binary double data properly from socket");
octave_stdout << "Cell count: " << cellCount << std::endl;
}
#endif
return; return;
} }

View File

@@ -84,41 +84,6 @@ void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16
OCTAVE_QUIT; OCTAVE_QUIT;
} }
octave_stdout << "Bytes count processed : " << byteCount << std::endl;
/*
while (socket.bytesAvailable() < (qint64)(byteCount))
{
if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs))
{
error((("Waiting for data: ") + socket.errorString()).toLatin1().data());
return;
}
OCTAVE_QUIT;
}
double* internalMatrixData = cellCornerValues.fortran_vec();
#if 0
double val;
for (octave_idx_type i = 0; i < valueCount; i++)
{
socketStream >> internalMatrixData[i];
}
#else
quint64 bytesRead = 0;
bytesRead = socket.read((char*)(internalMatrixData), byteCount);
if (byteCount != bytesRead)
{
error("Could not read binary double data properly from socket");
octave_stdout << "Cell count: " << cellCount << std::endl;
}
#endif
*/
return; return;
} }