/** Retrieves source for a shader object with GLES id @param shader_id. * * @param shader_id GLES id of a shader object to retrieve source for. * * @return String instance containing the shader source. **/ std::string TestCaseBase::getShaderSource(glw::GLuint shader_id) { const glw::Functions& gl = m_context.getRenderContext().getFunctions(); glw::GLint length = 0; gl.getShaderiv(shader_id, GL_SHADER_SOURCE_LENGTH, &length); std::vector<char> result_vec(length + 1); gl.getShaderSource(shader_id, length + 1, NULL, &result_vec[0]); GLU_EXPECT_NO_ERROR(gl.getError(), "Could not retrieve shader source!"); return std::string(&result_vec[0]); }
/** Retrieves compilation OR linking info log for a shader/program object with GLES id * @param id. * * @param is_compilation_info_log true if @param id is a GLES id of a shader object; * false if it represents a program object. * @param id GLES id of a shader OR a program object to * retrieve info log for. * * @return String instance containing the log.. **/ std::string TestCaseBase::getInfoLog(LOG_TYPE log_type, glw::GLuint id) { const glw::Functions& gl = m_context.getRenderContext().getFunctions(); glw::GLint n_characters = 0; /* Retrieve amount of characters needed to store the info log (terminator-inclusive) */ switch (log_type) { case LT_SHADER_OBJECT: gl.getShaderiv(id, GL_INFO_LOG_LENGTH, &n_characters); break; case LT_PROGRAM_OBJECT: gl.getProgramiv(id, GL_INFO_LOG_LENGTH, &n_characters); break; case LT_PIPELINE_OBJECT: gl.getProgramPipelineiv(id, GL_INFO_LOG_LENGTH, &n_characters); break; default: TCU_FAIL("Invalid parameter"); } /* Check if everything is fine so far */ GLU_EXPECT_NO_ERROR(gl.getError(), "Could not query info log length!"); /* Allocate buffer */ std::vector<char> result_vec(n_characters + 1); /* Retrieve the info log */ switch (log_type) { case LT_SHADER_OBJECT: gl.getShaderInfoLog(id, n_characters + 1, 0, &result_vec[0]); break; case LT_PROGRAM_OBJECT: gl.getProgramInfoLog(id, n_characters + 1, 0, &result_vec[0]); break; case LT_PIPELINE_OBJECT: gl.getProgramPipelineInfoLog(id, n_characters + 1, 0, &result_vec[0]); break; } GLU_EXPECT_NO_ERROR(gl.getError(), "Could not retrieve info log!"); return std::string(&result_vec[0]); }
inline void reduce_result(ResultT& result, const ResultT& local_result) { if(common::PE::Comm::instance().is_active()) { const Uint size = local_result.size(); std::vector<Real> local_vec(&local_result[0], &local_result[0]+size); std::vector<Real> result_vec(size); common::PE::Comm::instance().all_reduce(common::PE::plus(), local_vec, result_vec); for(Uint i = 0; i != size; ++i) { result[i] = result_vec[i]; } } else { result = local_result; } }
void avtConnComponentsCentroidQuery::PostExecute(void) { // get # of cells per component (from all processors) int *sum_res_int = new int[nComps]; SumIntArrayAcrossAllProcessors(&nCellsPerComp[0], sum_res_int, nComps); memcpy(&nCellsPerComp[0],sum_res_int,nComps * sizeof(int)); delete [] sum_res_int; // get centroid values (from all processors) double *sum_res_dbl = new double[nComps]; SumDoubleArrayAcrossAllProcessors(&xCentroidPerComp[0], sum_res_dbl, nComps); memcpy(&xCentroidPerComp[0],sum_res_dbl,nComps * sizeof(double)); SumDoubleArrayAcrossAllProcessors(&yCentroidPerComp[0], sum_res_dbl, nComps); memcpy(&yCentroidPerComp[0],sum_res_dbl,nComps * sizeof(double)); SumDoubleArrayAcrossAllProcessors(&zCentroidPerComp[0], sum_res_dbl, nComps); memcpy(&zCentroidPerComp[0],sum_res_dbl,nComps * sizeof(double)); delete [] sum_res_dbl; // create output message if(PAR_Rank() == 0) { std::string msg = ""; char buff[2048]; if(nComps == 1) {SNPRINTF(buff,2048,"Found %d connected component\n",nComps);} else {SNPRINTF(buff,2048,"Found %d connected components\n",nComps);} msg += buff; // pack values into a a single vector for query output std::vector<double> result_vec(nComps *3); for(int i=0;i<nComps;i++) { // get number of cells for current component double n_comp_cells = (double)nCellsPerComp[i]; // calculate centriod values for the current component xCentroidPerComp[i] /= n_comp_cells; yCentroidPerComp[i] /= n_comp_cells; zCentroidPerComp[i] /= n_comp_cells; // pack into result vector result_vec[i*3 + 0] = xCentroidPerComp[i]; result_vec[i*3 + 1] = yCentroidPerComp[i]; result_vec[i*3 + 2] = zCentroidPerComp[i]; } std::string format = "Component %d [%d cells] Centroid = (" + queryAtts.GetFloatFormat() +"," + queryAtts.GetFloatFormat() +"," + queryAtts.GetFloatFormat() +")\n"; // prepare the output message for(int i=0;i<nComps;i++) { SNPRINTF(buff,1024, format.c_str(), i, nCellsPerComp[i], xCentroidPerComp[i], yCentroidPerComp[i], zCentroidPerComp[i]); msg += buff; } // set result message SetResultMessage(msg); // set result values SetResultValues(result_vec); } }