void read_file(char *name) { FILE *f = fopen(name, "rb"); if (!f) { fprintf(stderr, "Error: Cannot open file\n"); return; } unsigned int count; fread(&count, sizeof(unsigned int), 1, f); unsigned int *buf = alloca(count * sizeof(unsigned int)); if (!buf) { return; } read_elements(f, buf, count); }
int read_ele_file(const char *ele_filename, triangulateio *input, int firstnode){ int error_value = 0; FILE *ele_file; ele_file = fopen(ele_filename, "r"); if (ele_file == (FILE *) NULL) { printf(" Error: Cannot access file %s.\n", ele_filename); return FILE_ERR; } error_value = read_elements_header(ele_file, input); if (error_value != SUCCESS) return error_value; allocate_elements(input); error_value = read_elements(ele_file, input, firstnode); if (error_value != SUCCESS) return error_value; return SUCCESS; }
int32_t psi_demonstrator(int32_t argc, char** argv) { double epsilon=1.2; uint64_t bytes_sent=0, bytes_received=0, mbfac; uint32_t nelements=0, elebytelen=16, symsecbits=128, intersect_size = 0, i, j, ntasks=1, pnelements, *elebytelens, *res_bytelens, nclients = 2; uint16_t port=7766; uint8_t **elements, **intersection; bool detailed_timings=false; string address="127.0.0.1"; timeval t_start, t_end; vector<CSocket> sockfd(ntasks); string filename; role_type role = (role_type) 0; psi_prot protocol; mbfac=1024*1024; read_psi_demo_options(&argc, &argv, &role, &protocol, &filename, &address, &nelements, &detailed_timings); if(role == FOLLOWER) { if(protocol == TTP) { sockfd.resize(nclients); listen(address.c_str(), port, sockfd.data(), nclients); } else listen(address.c_str(), port, sockfd.data(), ntasks); } else { for(i = 0; i < ntasks; i++) connect(address.c_str(), port, sockfd[i]); } gettimeofday(&t_start, NULL); //read in files and get elements and byte-length from there read_elements(&elements, &elebytelens, &nelements, filename); if(detailed_timings) { gettimeofday(&t_end, NULL); } if(protocol != TTP) pnelements = exchange_information(nelements, elebytelen, symsecbits, ntasks, protocol, sockfd[0]); //cout << "Performing private set-intersection between " << nelements << " and " << pnelements << " element sets" << endl; if(detailed_timings) { cout << "Time for reading elements:\t" << fixed << std::setprecision(2) << getMillies(t_start, t_end)/1000 << " s" << endl; } crypto crypto(symsecbits);//, (uint8_t*) const_seed); switch(protocol) { case NAIVE: intersect_size = naivepsi(role, nelements, pnelements, elebytelens, elements, &intersection, &res_bytelens, &crypto, sockfd.data(), ntasks); break; case TTP: intersect_size = ttppsi(role, nelements, elebytelens, elements, &intersection, &res_bytelens, &crypto, sockfd.data(), ntasks); break; case DH_ECC: intersect_size = dhpsi(role, nelements, pnelements, elebytelens, elements, &intersection, &res_bytelens, &crypto, sockfd.data(), ntasks); break; case OT_PSI: intersect_size = otpsi(role, nelements, pnelements, elebytelens, elements, &intersection, &res_bytelens, &crypto, sockfd.data(), ntasks, epsilon, detailed_timings); break; default: intersect_size = otpsi(role, nelements, pnelements, elebytelens, elements, &intersection, &res_bytelens, &crypto, sockfd.data(), ntasks, epsilon, detailed_timings); break; } gettimeofday(&t_end, NULL); if(role == LEADER) { cout << "Computation finished. Found " << intersect_size << " intersecting elements:" << endl; if(!detailed_timings) { for(i = 0; i < intersect_size; i++) { //cout << i << ": \t"; for(j = 0; j < res_bytelens[i]; j++) { cout << intersection[i][j]; } cout << endl; } } for(i = 0; i < intersect_size; i++) { free(intersection[i]); } if(intersect_size > 0) free(res_bytelens); } for(i = 0; i < sockfd.size(); i++) { bytes_sent += sockfd[i].get_bytes_sent(); bytes_received += sockfd[i].get_bytes_received(); } if(detailed_timings) { cout << "Required time:\t" << fixed << std::setprecision(1) << getMillies(t_start, t_end)/1000 << " s" << endl; cout << "Data sent:\t" << ((double)bytes_sent)/mbfac << " MB" << endl; cout << "Data received:\t" << ((double)bytes_received)/mbfac << " MB" << endl; } for(i = 0; i < nelements; i++) free(elements[i]); free(elements); free(elebytelens); return 1; }
ErrorCode ReadTemplate::load_file(const char* filename, const EntityHandle *file_set, const FileOptions& opts, const ReaderIface::SubsetList* subset_list, const Tag* /*file_id_tag*/) { if (subset_list) { // See src/moab/ReaderIface.hpp, definition of SubsetList struct; this basically specifies // an integer tag and tag values for sets to read on this proc, or a part number and total # parts // for reading a trivial partition of entities } // Save filename to member variable so we don't need to pass as an argument // to called functions fileName = filename; // Process options; see src/FileOptions.hpp for API for FileOptions class, and doc/metadata_info.doc for // a description of various options used by some of the readers in MOAB ErrorCode result = process_options(opts);MB_CHK_SET_ERR(result, fileName << ": problem reading options"); // Open file; filePtr is member of ReadTemplate, change to whatever mechanism is used to identify file FILE* filePtr = fopen(fileName, "r"); if (!filePtr) { MB_SET_ERR(MB_FILE_DOES_NOT_EXIST, fileName << ": fopen returned error"); } // Read number of verts, elements, sets long num_verts = 0, num_elems = 0, num_sets = 0; // read_ents keeps a running set of entities read from this file, including vertices, elements, and sets; // these will get added to file_set (if input) at the end of the read Range read_ents; // start_vertex is passed back so we know how to convert indices from the file into vertex handles; most // of the time this is done by adding start_vertex to the (0-based) index; if the index is 1-based, you also // need to subtract one; see read_elements for details EntityHandle start_vertex; result = read_vertices(num_verts, start_vertex, read_ents); if (MB_SUCCESS != result) { fclose(filePtr); return result; } // Create/read elements; this template assumes that all elements are the same type, so can be read in a single // call to read_elements, and kept track of with a single start_elem handle. If there are more entity types, // might have to keep these start handles in an array/vector. start_elem is only really needed if you're reading // sets later, and need to convert some file-based index to an entity handle EntityHandle start_elem; result = read_elements(num_elems, start_vertex, start_elem, read_ents); if (MB_SUCCESS != result) { fclose(filePtr); return result; } // Read/create entity sets; typically these sets have some tag identifying what they're for, see doc/metadata_info.doc // for examples of different kinds of sets and how they're marked result = create_sets(num_sets, start_vertex, num_verts, start_elem, num_elems, read_ents); if (MB_SUCCESS != result) { fclose(filePtr); return result; } // Finally, add all read_ents into the file set, if one was input if (file_set && *file_set) { result = mbImpl->add_entities(*file_set, read_ents); if (MB_SUCCESS != result) { fclose(filePtr); return result; } } fclose(filePtr); return result; }