Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenMP循环内部禁止抛出异常 #12

Merged
merged 5 commits into from
Apr 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/doxygen/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ EXCLUDE = ./doc \
./data \
./TODO \
./seims/bin \
./seims/include \
./seims/database \
./seims/src/taudem \
./seims/src/metis \
Expand Down
2 changes: 1 addition & 1 deletion seims/src/seims_main/main/main_omp/invoke.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int MainMongoDB(string modelPath, char *host, int port, int scenarioID, int numT
/// Return success
return 0;
}
catch (ModelException e) {
catch (ModelException& e) {
cout << e.toString() << endl;
exit(EXIT_FAILURE);
}
Expand Down
11 changes: 7 additions & 4 deletions seims/src/seims_main/modules/climate/ITP/Interpolate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ int Interpolate::Execute() {
//for (int j = 0; j < m_nStatioins; ++j)
// cout<<m_stationData[j]<<",";
//cout<<endl;

#pragma omp parallel for
size_t errCount = 0;
#pragma omp parallel for reduction(+: errCount)
for (int i = 0; i < m_nCells; ++i) {
int index = 0;
float value = 0.f;
Expand All @@ -48,11 +48,11 @@ int Interpolate::Execute() {
index = i * m_nStatioins + j;
//cout<<m_stationData[j]<<",";
//cout<<endl;
value += m_stationData[j] * m_weights[index];
if (value != value) {
errCount++;
cout << "CELL:" << i << ", Site: " << j << ", Weight: " << m_weights[index] <<
", siteData: " << m_stationData[j] << ", Value:" << value << ";" << endl;
throw ModelException(MID_ITP, "Execute", "Error occurred in weight data!\n");
//throw ModelException(MID_ITP, "Execute", "Error occurred in weight data!\n");
}

if (m_vertical) {
Expand All @@ -64,6 +64,9 @@ int Interpolate::Execute() {
}
m_itpOutput[i] = value;
}
if (errCount > 0) {
throw ModelException(MID_ITP, "Execute", "Error occurred in weight data!\n");
}
//for (int i = 0; i < m_nCells; ++i)
// cout<<m_output[i]<<",";
//Output1DArrayToTxtFile(m_nCells, m_output, "G:\\data_m\\itp.txt");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ void DiffusiveWave::SetValue(const char *key, float data) {
} else if (StringMatch(sk, VAR_CH_MANNING_FACTOR)) { /// TODO: add to mongodb database
m_manningScalingFactor = data;
} else {
throw ModelException(MID_CH_DW, "SetSingleData", "Parameter " + sk
throw ModelException(MID_CH_DW, "SetValue", "Parameter " + sk
+ " does not exist. Please contact the module developer.");
}

Expand Down
22 changes: 15 additions & 7 deletions seims/src/seims_main/modules/hydrology/CH_MSK/Muskingum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,13 @@ void Muskingum::initialOutputs() {
}
}

void Muskingum::ChannelFlow(int iReach, int iCell, int id, float qgEachCell) {
bool Muskingum::ChannelFlow(int iReach, int iCell, int id, float qgEachCell) {
float qUpNew = 0.f;

if (iReach == 0 && iCell == 0) {
qUpNew = m_qUpReach;
}


// inflow from upstream channel
if (iCell == 0)// inflow of this cell is the last cell of the upstream reach
{
Expand Down Expand Up @@ -316,7 +315,8 @@ void Muskingum::ChannelFlow(int iReach, int iCell, int id, float qgEachCell) {
cout << "Error in function Muskingum::ChannelFlow. \n";
cout << "The weights are: " << weights.c1 << ", " << weights.c2 << ", " << weights.c3 << endl;
cout << "qUpNew: " << qUpNew << "\tqUpPre: " << m_qUpCh[iReach][iCell] << "\tqNew: " << qNew << endl;
throw ModelException(MID_CH_MSK, "ChannelFlow", "Error occurred.");
//throw ModelException(MID_CH_MSK, "ChannelFlow", "Error occurred.");
return false;
}

float tmp = m_chStorage[iReach][iCell] + (qUpNew - qNew) * weights.dt;
Expand All @@ -334,6 +334,7 @@ void Muskingum::ChannelFlow(int iReach, int iCell, int id, float qgEachCell) {

q /= stepCount;
m_qCh[iReach][iCell] = q;
return true;
}

int Muskingum::Execute() {
Expand All @@ -342,7 +343,7 @@ int Muskingum::Execute() {
CheckInputData();

//Output1DArray(m_nCells, m_prec, "f:\\p2.txt");
map < int, vector < int > > ::iterator
map<int, vector<int> > ::iterator
it;
//cout << "reach layer number: " << m_reachLayers.size() << endl;
for (it = m_reachLayers.begin(); it != m_reachLayers.end(); it++) {
Expand All @@ -351,17 +352,24 @@ int Muskingum::Execute() {
int nReaches = it->second.size();
//cout << "reach number:" << nReaches << endl;
// the size of m_reachLayers (map) is equal to the maximum stream order
bool exceptionOccurredFlag = false;
#pragma omp parallel for
for (int i = 0; i < nReaches; ++i) {
int reachIndex = it->second[i]; // index in the array
vector<int> &vecCells = m_reachs[reachIndex];
int n = vecCells.size();
float qgEachCell = m_qg[reachIndex + 1] / n;
for (int iCell = 0; iCell < n; ++iCell) {
ChannelFlow(reachIndex, iCell, vecCells[iCell], qgEachCell);
#pragma omp flush (exceptionOccurredFlag)
if (!exceptionOccurredFlag) {
exceptionOccurredFlag = ChannelFlow(reachIndex, iCell, vecCells[iCell], qgEachCell);
#pragma omp flush (exceptionOccurredFlag)
}
m_qSubbasin[reachIndex] = m_qCh[reachIndex][n - 1];
}
m_qSubbasin[reachIndex] = m_qCh[reachIndex][n - 1];

}
if (exceptionOccurredFlag) {
throw ModelException(MID_CH_MSK, "ChannelFlow", "Error occurred.");
}
}
return 0;
Expand Down
15 changes: 5 additions & 10 deletions seims/src/seims_main/modules/hydrology/CH_MSK/Muskingum.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,11 @@ class Muskingum : public SimulationModule {
float GetDelta_t(float timeStep, float fmin, float fmax);

private:
///// deal with positive and negative float numbers
//float Power(float a, float n) {
// if (a >= 0) {
// return pow(a, n);
// } else {
// return -pow(-a, n);
// }
//}

void ChannelFlow(int iReach, int iCell, int id, float qgEachCell);
/*!
* \brief Channel flow routing based Muskingum.
* \return true for success, otherwise false.
*/
bool ChannelFlow(int iReach, int iCell, int id, float qgEachCell);

void initialOutputs();

Expand Down