本文整理汇总了C++中DCBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ DCBuffer类的具体用法?C++ DCBuffer怎么用?C++ DCBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DCBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: malloc
DCBuffer * DCFilter::readany(std::string *exceptionPorts, int numExc, std::string * port) {
char *inPortName;
int i;
// Reads the data using Anthill
char **c_exceptionPorts = (char **) malloc(numExc);
for(i = 0; i < numExc; i++) {
c_exceptionPorts[i] = (char *) (exceptionPorts[i]).c_str();
}
int bufSz = dsReadBufferAnyPort(&inPortName, c_exceptionPorts, numExc, recvBuf->getBufPtr(), recvBuf->getSize());
if(port != NULL)
*port = inPortName;
if (bufSz != EOW) {
// Pack the data in a DCBuffer
DCBuffer * dcBuf = new DCBuffer(bufSz);
memcpy(dcBuf->getPtr(), recvBuf->getBufPtr(), bufSz);
dcBuf->setUsedSize(bufSz);
return dcBuf;
}
// Received an EOW. There isn't more data to be received.
return NULL;
}
示例2: dsGetInputPortByName
// Returns NULL or non-NULL, depending on if anything is available or not
// when it is called.
DCBuffer * DCFilter::read_non_blocking(const std::string & portName) {
// Gets Anthill input port handler
InputPortHandler inPort = dsGetInputPortByName((char *) portName.c_str());
if(inPort == -1) {
string exitMsg = "read_non_blocking: There is no port "+portName+" in filter "+get_filter_name();
dsExit((char *)exitMsg.c_str());
}
// Reads the data using Anthill
int bufSz = dsReadNonBlockingBuffer(inPort, recvBuf->getBufPtr(), recvBuf->getSize());
if (bufSz == 0) {
// There is no data to be received now.
return NULL;
}
if (bufSz != EOW) {
// Pack the data in a DCBuffer
DCBuffer * dcBuf = new DCBuffer(bufSz);
memcpy(dcBuf->getPtr(), recvBuf->getBufPtr(), bufSz);
dcBuf->setUsedSize(bufSz);
return dcBuf;
}
// Received an EOW. There isn't more data to be received.
return NULL;
}
示例3: get_filter_name
int filterA::process(){
cout << "process " << get_filter_name() << " Id: "
<< get_global_filter_thread_id() << ". Rank: " << get_my_rank() << "\n";
DCBuffer * outBuffer = new DCBuffer(100);
outBuffer->pack("s", "Hellow!!!");
write (outBuffer, "out");
outBuffer->Delete();
DCBuffer * outBuffer1 = new DCBuffer(100);
outBuffer1->pack("s", "NonBlocking message.");
write_nocopy(outBuffer1, "out");
outBuffer1->Delete();
//filter_exit("Nao e' nada nao");
return 0;
}
示例4: process
int process()
{
int i;
int j;
DCBuffer * work = get_init_filter_broadcast();
std::string packet_size_and_num_packets;
work->Extract(& packet_size_and_num_packets);
std::vector<std::string> toks =
dcmpi_string_tokenize(packet_size_and_num_packets);
int num_packets = dcmpi_csnum(toks[1]);
for (i = 0; i < num_packets; i++) {
DCBuffer * b = readany();
char * p = b->getPtr();
for (j = 0; j < b->getUsedSize(); j++) {
char expected = (char)(j%256);
if (p[j] != expected) {
sleep(2);
std::cerr << "ERROR: expecting " << (int)expected
<< ", got " << (int)p[j]
<< ", j=" << j
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
std::cerr << *b;
// b->extended_print(cerr);
assert(0);
}
}
b->consume();
printf(".");
fflush(stdout);
}
printf("\n");
return 0;
}
示例5: DCBuffer
void ocvm_tessellator::do_tess(DCBuffer * input)
{
int4 sentinel;
int8 width, height;
int4 x, y, z;
uint1 threshold;
int4 color;
input->unpack("iBlliiii", &sentinel, &threshold,
&width, &height, &x, &y, &z,
&color);
const int hdrsz = 64;
input->resetExtract(hdrsz);
int8 cells_per_row = width / user_tessellation_x;
if (width % user_tessellation_x) {
cells_per_row++;
}
int8 total_cell_rows = height / user_tessellation_y;
if (height % user_tessellation_y) {
total_cell_rows++;
}
int new_sz = cells_per_row * total_cell_rows*sizeof(ocvm_sum_integer_type);
DCBuffer * out = new DCBuffer(
hdrsz + new_sz);
memset(out->getPtr(), 0, hdrsz + new_sz);
out->pack("iBlliiii", sentinel, threshold, cells_per_row, total_cell_rows,
x, y, z, color);
// std::cout << "tessellation: active on x,y,z of "
// << x << "," << y << "," << z << ", color " << color
// << " on host " << dcmpi_get_hostname(true) << endl;
out->setUsedSize(hdrsz + new_sz);
uint1 * src_base = (uint1*)input->getPtrExtract();
uint1 * src = src_base;
uint1 * src_end = src_base + width * height;
ocvm_sum_integer_type * dest = (ocvm_sum_integer_type*)(out->getPtr()+hdrsz);
ocvm_sum_integer_type * dest_end = (ocvm_sum_integer_type*)((char*)dest + new_sz);
register ocvm_sum_integer_type count;
int8 input_rows_covered = 0;
int cell, cell_member;
while (input_rows_covered < height) {
assert (dest < dest_end);
uint1 * row_end = src + width;
for (cell = 0; cell < cells_per_row; cell++) {
memcpy(&count, dest + cell, sizeof(ocvm_sum_integer_type));
for (cell_member = 0;
cell_member < user_tessellation_x && src < row_end;
cell_member++) {
count += *src;
src++;
}
memcpy(dest + cell, &count, sizeof(ocvm_sum_integer_type));
}
input_rows_covered++;
if (input_rows_covered % user_tessellation_y == 0) {
dest += cells_per_row;
}
}
// cout << "te2: " << *out << endl;
// std::cout << "tess sending out ";
// out->extended_print(cout);
write_nocopy(out, "0");
delete input;
}
示例6: main
//.........这里部分代码省略.........
for (u2 = 0; u2 < warp_filters_per_host; u2++) {
layout.add_port(readalls[u], "output",
computers[u*warp_filters_per_host + u2], "from_readall");
layout.add_port(computers[u*warp_filters_per_host + u2], "ack",
readalls[u], "ack");
}
}
for (u = 0; u < computers.size(); u++) {
for (u2 = 0; u2 < mappers.size(); u2++) { // assumes 1 mapper and 1 writer per host
if (computers[u]->get_param("myhostname") == writers[u2]->get_param("myhostname")) {
layout.add_port(computers[u], "to_" + writers[u2]->get_param("myhostname"), writers[u2], "0");
}
layout.add_port(computers[u], "to_m_" + mappers[u2]->get_param("myhostname"), mappers[u2], "0");
}
}
for (u = 0; u < mappers.size(); u++) {
for (u2 = 0; u2 < writers.size(); u2++) {
layout.add_port(mappers[u], "to_" + writers[u2]->get_param("myhostname"), writers[u2], "0");
}
}
mediator_add_client(layout, info, readalls);
mediator_add_client(layout, info, mapper_readalls);
mediator_add_client(layout, info, writers);
double before = dcmpi_doubletime();
std::string dim_timestamp = get_dim_output_timestamp();
layout.set_param_all("dim_timestamp", dim_timestamp);
DCFilter * console_filter = layout.execute_start();
DCBuffer * imgstr = new DCBuffer(image_descriptor_string.size()+1);
imgstr->pack("s", image_descriptor_string.c_str());
console_filter->write_broadcast(imgstr, "to_warper");
delete imgstr;
for (u = 0; u < jxd->num_control_points; u++) {
DCBuffer * out = new DCBuffer(4 * sizeof(float) + sizeof(uint));
/*
cout << jxd->correspondences[u]->origin_x << " " <<
jxd->correspondences[u]->origin_y << " " <<
jxd->correspondences[u]->endpoint_x << " " <<
jxd->correspondences[u]->endpoint_y << " " <<
jxd->correspondences[u]->weight << endl;
*/
out->pack("ffffi", jxd->correspondences[u]->origin_x,
jxd->correspondences[u]->origin_y,
jxd->correspondences[u]->endpoint_x,
jxd->correspondences[u]->endpoint_y,
jxd->correspondences[u]->weight);
console_filter->write_broadcast(out, "to_warper");
}
std::map<ImageCoordinate, std::pair<std::string, int8> > newfiles;
for (u = 0; u < descriptor.parts.size(); u++) {
DCBuffer * in = console_filter->read("from_warpwriter");
ImageCoordinate ic;
std::string output_filename;
int8 output_offset;
in->unpack("iiisl", &ic.x, &ic.y, &ic.z,
&output_filename, &output_offset);
newfiles[ic] = make_pair(output_filename, output_offset);
delete in;
}
示例7: answer_ps_queries
int answer_ps_queries(
DCFilter * console_filter,
const std::vector<std::string> & hosts,
ImageDescriptor original_image_descriptor,
ImageDescriptor prefix_sum_descriptor,
std::vector<PixelReq> query_points,
int zslice,
std::vector<std::vector<int8> > & results)
{
DCBuffer keep_going;
keep_going.pack("i", 1);
console_filter->write_broadcast(&keep_going, "0");
DCBuffer out;
out.pack("ssi",
"psquery",
tostr(prefix_sum_descriptor).c_str(),
zslice);
std::cout << "zslice is " << zslice << endl;
console_filter->write_broadcast(&out, "0");
// build cache
int tess_x, tess_y;
std::string extra = prefix_sum_descriptor.extra;
std::vector<std::string> toks = dcmpi_string_tokenize(extra);
tess_x = Atoi(toks[1]);
tess_y = Atoi(toks[3]);
std::string lpscache = toks[5];
toks = dcmpi_string_tokenize(lpscache, ":");
// fill lower-right-corner cache
std::map<std::string, std::string> lower_right_corner_cache;
for (uint u = 0; u < toks.size(); u++) {
const std::string & s = toks[u];
std::vector<std::string> toks2 = dcmpi_string_tokenize(s, "/");
lower_right_corner_cache[toks2[0]] = toks2[1];
std::cout << "cache: " << toks2[0] << "->" << toks2[1] << endl;
}
std::map<PixelReq, std::vector<int> > cached_contributions;
std::map<PixelReq, std::vector<PixelReq> > querypoint_pspoints;
#define INSERT(x,y) request_set.insert(PixelReq(x,y)); querypoint_pspoints[*it].push_back(PixelReq(x,y)); std::cout << "inserted " << x << "," << y << "\n";
SerialSet<PixelReq> request_set;
std::vector<PixelReq>::iterator it;
for (it = query_points.begin();
it != query_points.end();
it++) {
int8 psx, psy;
int8 new_x, new_y;
psx = it->x / tess_x;
psy = it->y / tess_y;
int chunk_x, chunk_y;
prefix_sum_descriptor.pixel_to_chunk(psx, psy, chunk_x, chunk_y);
if (chunk_x != 0 && chunk_y != 0) {
chunk_x--;
chunk_y--;
std::string key =
tostr(chunk_x) + "," +
tostr(chunk_y) + "," +
tostr(zslice);
std::string val = lower_right_corner_cache[key];
std::vector<std::string> toks = dcmpi_string_tokenize(val, ",");
std::vector<int> bgrvals;
for (uint u = 0; u < toks.size(); u++) {
bgrvals.push_back(Atoi(toks[u]));
}
cached_contributions[*it] = bgrvals;
std::cout << "cached_contribution for query point "
<< *it << " is "
<< val << endl;
}
while (1) {
if (prefix_sum_descriptor.bottommost_pixel_next_chunk_up(
psx, psy, new_x, new_y) == false) {
break;
}
INSERT(new_x, new_y);
psx = new_x;
psy = new_y;
}
psx = it->x / tess_x;
psy = it->y / tess_y;
while (1) {
if (prefix_sum_descriptor.rightmost_pixel_next_chunk_to_the_left(
psx, psy, new_x, new_y) == false) {
break;
}
INSERT(new_x, new_y);
psx = new_x;
psy = new_y;
}
psx = it->x / tess_x;
psy = it->y / tess_y;
//.........这里部分代码省略.........
示例8: main
int main(int argc, char * argv[])
{
uint u;
bool quiet = false;
while (argc-1 >= 1) {
if (!strcmp(argv[1], "-q")) {
quiet = true;
}
else {
break;
}
dcmpi_args_shift(argc, argv);
}
if ((argc-1) < 1) {
appname = argv[0];
usage();
}
for (int i = 1; i < argc; i++) {
std::string filename = argv[i];
if (!dcmpi_file_exists(filename)) {
std::cerr << "ERROR: file " << filename
<< " does not exist!"
<< std::endl << std::flush;
exit(1);
}
FILE * f;
int len = ocvm_file_size(filename);
char * contents = new char[len+1];
contents[len] = 0;
if ((f = fopen(filename.c_str(), "r")) == NULL) {
std::cerr << "ERROR: opening file"
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
exit(1);
}
if (fread(contents, len, 1, f) < 1) {
std::cerr << "ERROR: calling fread()"
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
exit(1);
}
if (fclose(f) != 0) {
std::cerr << "ERROR: calling fclose()"
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
exit(1);
}
ImageDescriptor original_image_descriptor;
original_image_descriptor.init_from_string(contents);
std::vector<std::string> hosts_vector =
original_image_descriptor.get_hosts();
DCLayout layout;
DCFilterInstance console("<console>", "con");
layout.add(console);
layout.use_filter_library("libocvmfilters.so");
// layout.add_propagated_environment_variable("DCMPI_FILTER_PATH", false);
for (u = 0; u < hosts_vector.size(); u++) {
DCFilterInstance * remover = new DCFilterInstance("ocvm_remover", tostr("remover") + tostr(u));
layout.add(remover);
if (quiet) {
remover->set_param("quiet", "yes");
}
remover->set_param("my_hostname", hosts_vector[u]);
remover->bind_to_host(hosts_vector[u]);
layout.add_port(&console, "out", remover, "in");
}
DCFilter * console_filter = layout.execute_start();
DCBuffer * imgstr = new DCBuffer();
imgstr->pack("s", contents);
delete[] contents;
console_filter->write_broadcast(imgstr, "out");
delete imgstr;
int rc = layout.execute_finish();
if (rc == 0) {
rc = remove(filename.c_str());
}
if (rc) {
std::cerr << "ERROR: " << rc << " in execute() or remove()"
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
exit(1);
}
if (!quiet) {
std::cout << "removed " << filename << endl;
}
}
return 0;
}
示例9: main
//.........这里部分代码省略.........
layout.add_port(rangefetcher, "0",
scaler, "from_rangefetcher");
layout.add_port(scaler, "to_rangefetcher",
rangefetcher, "0");
layout.add_port(scaler, "to_console", &console, "from_scaler");
}
std::vector< std::string> dest_hosts;
std::vector< std::string> client_hosts;
if (non_local_destination) {
dest_hosts = dest_host_scratch->get_hosts();
}
if (non_local_clients) {
client_hosts = client_host_scratch->get_hosts();
}
MediatorInfo info = mediator_setup(layout, 1, 1, input_hosts, client_hosts, dest_hosts);
mediator_add_client(layout, info, scalers);
mediator_add_client(layout, info, rangefetchers);
double before = dcmpi_doubletime();
std::string dim_timestamp = get_dim_output_timestamp();
layout.set_param_all("dim_timestamp", dim_timestamp);
layout.set_param_all("xs", tostr(xs));
layout.set_param_all("ys", tostr(ys));
layout.set_param_all("zs", tostr(zs));
DCFilter * console_filter = layout.execute_start();
std::map<ImageCoordinate, std::vector<std::string> > newfiles;
int newparts = xs*ys*zs*
original_image_descriptor.chunks_x*
original_image_descriptor.chunks_y*
original_image_descriptor.chunks_z;
std::cout << "newparts " << newparts << endl;
for (u = 0; u < newparts; u++) {
DCBuffer * in = console_filter->read("from_scaler");
ImageCoordinate ic;
std::string hn;
std::string output_filename;
int8 output_offset;
in->unpack("siiisl", &hn, &ic.x, &ic.y, &ic.z,
&output_filename, &output_offset);
std::vector<std::string> v;
v.push_back(hn);
v.push_back(output_filename);
v.push_back(tostr(output_offset));
newfiles[ic] = v;
delete in;
}
rc = layout.execute_finish();
if (rc) {
std::cerr << "ERROR: layout.execute() returned " << rc
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
exit(1);
}
else {
int i;
std::string message = "type BGRplanar\n";
message += "pixels_x " + tostr(original_image_descriptor.pixels_x*xs)+"\n";
message += "pixels_y " + tostr(original_image_descriptor.pixels_y*ys)+"\n";
message += "pixels_z " + tostr(original_image_descriptor.pixels_z*zs)+"\n";
message += "chunks_x " + tostr(original_image_descriptor.chunks_x*xs)+"\n";
message += "chunks_y " + tostr(original_image_descriptor.chunks_y*ys)+"\n";
message += "chunks_z " + tostr(original_image_descriptor.chunks_z*zs)+"\n";
message += "chunk_dimensions_x";
示例10: main
//.........这里部分代码省略.........
layout.add_port(cxx_aligner, "to_buddy", cxx_buddy, "0");
layout.add_port(cxx_buddy, "to_j", java_aligner, "0");
layout.add_port(java_aligner, "0", cxx_buddy, "from_j");
layout.add_port(cxx_buddy, "to_mst",
&maximum_spanning_tree, "from_aligners");
}
std::vector< std::string> dest_hosts;
std::vector< std::string> client_hosts;
if (non_local_destination) {
dest_hosts = dest_host_scratch->get_hosts();
}
if (non_local_clients) {
client_hosts = client_host_scratch->get_hosts();
}
MediatorInfo info = mediator_setup(layout, 2, 1, input_hosts, client_hosts, dest_hosts);
mediator_add_client(layout, info, cxx_aligners);
layout.set_param_all("channelOfInterest", channelOfInterest);
layout.set_param_all("numAligners", tostr(cxx_aligners.size()));
layout.set_param_all(
"nXChunks", tostr(original_image_descriptor.chunks_x));
layout.set_param_all(
"nYChunks", tostr(original_image_descriptor.chunks_y));
layout.set_param_all("subimage_width", tostr(subimage_width));
layout.set_param_all("subimage_height", tostr(subimage_height));
layout.set_param_all("subimage_overlap", tostr(subimage_overlap));
if (getenv("OCVMSTITCHMON")) {
std::vector<std::string> tokens = dcmpi_string_tokenize(
getenv("OCVMSTITCHMON"), ":");
int s = ocvmOpenClientSocket(tokens[0].c_str(), Atoi(tokens[1]));
std::string message = "setup " +
tostr(original_image_descriptor.chunks_x) + " " +
tostr(original_image_descriptor.chunks_y) + "\n";
rc = ocvm_write_message(s, message);
if (rc) {
std::cerr << "ERROR: " << rc << " writing to socket "
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
}
close(s);
}
DCFilter * console_filter = layout.execute_start();
std::string image_descriptor_string = tostr(original_image_descriptor);
DCBuffer * imgstr = new DCBuffer(image_descriptor_string.size()+1);
imgstr->pack("s", image_descriptor_string.c_str());
console_filter->write_broadcast(imgstr, "to_cxx_aligner");
delete imgstr;
DCBuffer * finalized_offsets = console_filter->read("from_mst");
int reps = 0;
int8 maxX, maxY;
int8 offset_x, offset_y;
finalized_offsets->unpack("ll", &maxX, &maxY);
std::string finalized_offsets_str = "finalized_offsets " +
tostr(maxX) + "/" + tostr(maxY);
while (finalized_offsets->getExtractAvailSize() > 0) {
finalized_offsets_str += ",";
finalized_offsets->unpack("ll", &offset_x, &offset_y);
finalized_offsets_str += tostr(offset_x) + ":" + tostr(offset_y);
reps++;
}
rc = layout.execute_finish();
if (rc) {
std::cerr << "ERROR: layout.execute() returned " << rc
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
exit(1);
}
else {
FILE * f;
if ((f = fopen(output_filename.c_str(), "w")) == NULL) {
std::cerr << "ERROR: errno=" << errno << " opening file"
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
exit(1);
}
if (fwrite(finalized_offsets_str.c_str(),
finalized_offsets_str.size(), 1, f) < 1) {
std::cerr << "ERROR: errno=" << errno << " calling fwrite()"
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
exit(1);
}
if (fclose(f) != 0) {
std::cerr << "ERROR: errno=" << errno << " calling fclose()"
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
exit(1);
}
}
std::cout << "elapsed autoalign "
<< dcmpi_doubletime() - time_start << " seconds\n";
return rc;
}
示例11: get_bind_host
int ocvm_dim_writer2::process()
{
std::cout << "dim writer on "
<< get_bind_host()
<< " launching\n" << flush;
DCBuffer * in;
std::string output_filename;
std::string mode;
std::vector<std::string> dirs_made;
std::vector<std::string> dirs_rename_to;
while (1) {
in = read_until_upstream_exit("0");
if (!in) {
break;
}
in->unpack("ss", &output_filename, &mode);
std::string d = dcmpi_file_dirname(output_filename);
std::string tstamp = dcmpi_file_basename(d);
std::string scratch_dir = dcmpi_file_dirname(d);
std::string temporary_dir = scratch_dir + "/.tmp." + tstamp;
std::string new_filename =
temporary_dir + "/" + dcmpi_file_basename(output_filename);
if (!dcmpi_file_exists(temporary_dir)) {
if (dcmpi_mkdir_recursive(temporary_dir)) {
if (errno != EEXIST) {
std::cerr << "ERROR: making directory " << temporary_dir
<< " on " << dcmpi_get_hostname()
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
exit(1);
}
}
else {
dirs_made.push_back(temporary_dir);
dirs_rename_to.push_back(scratch_dir + "/" + tstamp);
}
}
assert(dcmpi_file_exists(temporary_dir));
FILE * f;
if ((f = fopen(new_filename.c_str(), mode.c_str())) == NULL) {
std::cerr << "ERROR: opening " << new_filename
<< " for mode " << mode
<< " on host " << dcmpi_get_hostname()
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
exit(1);
}
if (fwrite(in->getPtrExtract(), in->getExtractAvailSize(), 1, f) < 1) {
std::cerr << "ERROR: calling fwrite()"
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
exit(1);
}
if (fclose(f) != 0) {
std::cerr << "ERROR: calling fclose()"
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
exit(1);
}
delete in;
}
// barrier
int nwriters = get_param_as_int("nwriters");
if (nwriters > 1) {
DCBuffer broadcast;
write_broadcast(&broadcast, "barrier");
for (int i = 0; i < nwriters-1; i++) {
DCBuffer* input = read ("barrier");
delete input;
}
}
for (unsigned int u = 0; u < dirs_made.size(); u++) {
rename(dirs_made[u].c_str(), dirs_rename_to[u].c_str());
}
std::cout << "dim writer on "
<< get_bind_host()
<< " exiting\n";
return 0;
}
示例12: process
int ocvm_dim_writer::process()
{
std::string output_directory;
int x1, y1, x2, y2, z;
int i, j;
DCBuffer * in;
const char * mode;
//while (1) {
//in = read_until_upstream_exit("0");
in = read("0");
//if (!in) {
// break;
//}
in->unpack("siiiii",
&output_directory, &x1, &y1,
&x2, &y2, &z);
in->consume();
// cout << "dimwriter on " << dcmpi_get_hostname()
// << ": writing to "
// << output_filename << endl;
std::string containing_dir = dcmpi_file_dirname(output_directory);
if (!dcmpi_file_exists(containing_dir)) {
if (dcmpi_mkdir_recursive(containing_dir)) {
std::cerr << "ERROR: making directories on "
<< dcmpi_get_hostname()
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
}
}
assert(dcmpi_file_exists(containing_dir));
FILE * f;
mode = "w";
for (i = y1; i <= y2; i++) {
for (j = x1; j <= x2; j++) {
std::string output_filename = output_directory + tostr(j) + "_" + tostr(i) + "_0";
if ((f = fopen(output_filename.c_str(), mode)) == NULL) {
std::cerr << "ERROR: opening " << output_filename
<< " for mode " << mode
<< " on host " << dcmpi_get_hostname()
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
exit(1);
}
in = read("0");
if (compress) {
in->decompress();
}
if (fwrite(in->getPtr(), in->getUsedSize(), 1, f) < 1) {
std::cerr << "ERROR: calling fwrite()"
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
exit(1);
}
in->consume();
if (fclose(f) != 0) {
std::cerr << "ERROR: calling fclose()"
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
exit(1);
}
}
}
//}
return 0;
}
示例13: get_param
int ocvmqueryhandler::process()
{
std::string my_workload = get_param("my_workload");
off_t color_offset = (off_t)Atoi(get_param("color_offset"));
off_t row_size = (off_t)Atoi(get_param("num_columns"));
int partial = Atoi(get_param("partial"));
#ifdef DEBUG
// cout << dcmpi_get_hostname() << " " << get_distinguished_name() << " workload: \n" << my_workload << endl;
#endif
DCBuffer *outb;
std::vector< std::string> lines = str_tokenize(my_workload, "\n");
outb = new DCBuffer(lines.size()*sizeof(ocvm_sum_integer_type)*250);
outb->Append(get_param("myhostname"));
typedef std::map< std::string, std::map< off_t, std::string > >
offset_value_mapping ;
offset_value_mapping offset_value;
for (int i = 0; i < (int)lines.size(); i++) {
std::vector< std::string> tokens = str_tokenize(lines[i]);
std::string filename = tokens[0];
if (offset_value.count(filename) == 0) {
offset_value[filename] =
std::map< off_t, std::string >();
}
FILE * psumf = fopen(filename.c_str(),"r");
if (!psumf) {
std::cerr << "ERROR: opening file " << filename
<< " on host " << dcmpi_get_hostname(true)
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
exit(1);
}
for (int j = 1; j < (int)tokens.size(); j++) {
off_t chunk_offset = (off_t)Atoi(tokens[j]);
ocvm_sum_integer_type value_at_point;
std::string values_at_point_string = "";
std::map< off_t, std::string > &
value_mapping = offset_value[filename];
if (value_mapping.count(chunk_offset) == 0) {
for (int k = 0; k < 3; k++) {
off_t seek_offset;
seek_offset = (chunk_offset + k * color_offset);
if (fseeko(psumf, seek_offset, SEEK_SET) != 0) {
std::cerr << "ERROR: seeking to position "
<< chunk_offset << " in file "
<< filename
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
exit(1);
}
if (fread(&value_at_point, sizeof(ocvm_sum_integer_type),
1, psumf) < 1) {
std::cerr << "ERROR: calling fread"
<< " at " << __FILE__
<< ":" << __LINE__
<< std::endl << std::flush;
exit(1);
}
outb->Append(value_at_point);
values_at_point_string += tostr(value_at_point) + " ";
}
value_mapping[chunk_offset] = values_at_point_string;
}
else {
std::vector< std::string > values_at_point = str_tokenize(value_mapping[chunk_offset]);
for (int k = 0; k < 3; k++) {
value_at_point = (ocvm_sum_integer_type)Atoi(values_at_point[k]);
outb->Append(value_at_point);
}
}
}
fclose(psumf);
}
write(outb, "0");
return 0;
}
示例14: dcmpi_doubletime
int ocvm_ppm_partitioner::process()
{
cout << "ocvm_ppm_partitioner: invoked \n";
double before = dcmpi_doubletime();
uint u;
FILE * f_dim;
int i, j;
std::string input_filename = get_param("input_filename");
std::string host_scratch_filename = get_param("host_scratch_filename");
HostScratch host_scratch(host_scratch_filename);
std::string output_filename = get_param("output_filename");
std::string dim_timestamp = get_param("dim_timestamp");
int nnodes = host_scratch.components.size();
PPMDescriptor ppm(input_filename);
if (ppm.pixels_y < nnodes) {
std::cerr << "ERROR: can't handle such a tiny image"
<< " at " << __FILE__ << ":" << __LINE__
<< std::endl << std::flush;
exit(1);
}
std::cout << "ppm.pixels_x: " << ppm.pixels_x << endl;
std::cout << "ppm.pixels_y: " << ppm.pixels_y << endl;
int output_tiles = nnodes;
int8 sz = 3 * ppm.pixels_x * ppm.pixels_y;
while ((sz / output_tiles) > MB_2) {
output_tiles *= 2;
}
std::cout << "output_tiles " << output_tiles << endl;
int chunks_per_host = output_tiles / nnodes;
int pixel_rows_per_tile_norm = ppm.pixels_y / output_tiles;
int pixel_rows_per_tile_rem = ppm.pixels_y % output_tiles;
int pixel_rows_per_tile_last = ppm.pixels_y - (pixel_rows_per_tile_norm *
(output_tiles-1));
std::cout << pixel_rows_per_tile_norm << endl;
std::cout << pixel_rows_per_tile_rem << endl;
std::cout << pixel_rows_per_tile_last << endl;
int hostid = 0;
int ckthisid = 0;
std::vector<int> dims_y;
std::vector<std::string> parts;
for (int t = 0; t < output_tiles; t++) {
int pixel_rows = pixel_rows_per_tile_norm;
if (t == output_tiles-1) {
pixel_rows = pixel_rows_per_tile_last;
}
else if (pixel_rows_per_tile_rem) {
pixel_rows_per_tile_rem--;
pixel_rows += 1;
pixel_rows_per_tile_last--;
}
dims_y.push_back(pixel_rows);
//std::cout << "malloc of "<<(pixel_rows * ppm.pixels_x * 3)<<endl;
unsigned char * data_rgb =
new unsigned char[pixel_rows * ppm.pixels_x * 3];
std::string output_prefix =
(host_scratch.components[hostid])[1] + "/" +
dim_timestamp + "/" + dcmpi_file_basename(input_filename)
+ ".";
int x = 0;
int y = t;
std::string output_fn =
output_prefix + "x" +
tostr(x) + "_y" +
tostr(y);
char partline[4096];
snprintf(partline, sizeof(partline),
"part %d %d %d %s %s",
x,
y,
0,
((host_scratch.components[hostid])[0]).c_str(),
output_fn.c_str());
parts.push_back(partline);
int npixels = pixel_rows * ppm.pixels_x;
int chunk_sz = npixels*3;
DCBuffer * outb = new DCBuffer(8+output_fn.size() + 8+1+
chunk_sz);
outb->pack("ss", output_fn.c_str(), "w");
ppm.getrows(pixel_rows, data_rgb);
// convert from RGB to planar BGR
unsigned char * dest = (unsigned char*)outb->getPtrFree();
for (int chan = 0; chan < 3; chan++) {
unsigned char * src = data_rgb + (2 - chan);
for (int v = 0; v < npixels; v++) {
*dest = *src;
dest++;
src += 3;
}
}
outb->incrementUsedSize(chunk_sz);
write_nocopy(outb, "towriter_" + tostr(hostid));
delete[] data_rgb;
ckthisid++;
if (ckthisid==chunks_per_host) {
ckthisid=0;
//.........这里部分代码省略.........
示例15: void_to_dcbuffer
DCBuffer* void_to_dcbuffer(void *buf, int bufSz) {
DCBuffer * dcBuf = new DCBuffer(bufSz);
memcpy(dcBuf->getPtr(), buf, bufSz);
dcBuf->setUsedSize(bufSz);
return dcBuf;
}