Example #1
0
 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;
 }
Example #2
0
int main(int argc, char * argv[])
{
    appname = argv[0];
    if (((argc-1) != 3)) {
        usage();
    }

    DCLayout layout;
    layout.use_filter_library("liball2allfilters.so");
    DCFilterInstance console("<console>", "console");
    layout.add(console);
    int lines = dcmpi_file_lines(argv[1]);
    int i, j;
    std::vector<DCFilterInstance*> filters;
    for (i = 0; i < lines; i++) {
        DCFilterInstance * f = new DCFilterInstance(
            "all2all", "all2all_" +  dcmpi_to_string(i));
        filters.push_back(f);
        layout.add(f);
        f->set_param("myid", dcmpi_to_string(i));
    }
    for (i = 0; i < lines; i++) {
        for (j = 0; j < lines; j++) {
            if (i != j) {
                layout.add_port(filters[i], dcmpi_to_string(j),
                                filters[j], "incoming");
            }
        }
        layout.add_port(filters[i], "ready", &console, "ready");
        layout.add_port(&console, "ready", filters[i], "ready");
    }
    layout.set_param_all("packet_size", argv[2]);
    layout.set_param_all("num_packets", argv[3]);
    layout.set_param_all("filter_count", dcmpi_to_string(lines));
    layout.set_exec_host_pool_file(argv[1]);

    DCFilter * c = layout.execute_start();

    // wait till all are ready
    cout << "waiting for all filters to be ready..." << flush;
    for (i = 0; i < lines; i++) {
        DCBuffer * b = c->read("ready");
        b->consume();
    }
    DCBuffer goBuf;
    for (i = 0; i < lines; i++) {
        c->write(&goBuf, "ready");
    }
    cout << "done\nall filters are ready, test is commencing\n";
    double tstart = dcmpi_doubletime();
    int rc = layout.execute_finish();
    double tstop = dcmpi_doubletime();
    double elapsed = tstop - tstart;
    double MB = ((dcmpi_csnum(argv[2]) * (dcmpi_csnum(argv[3])) *
                  (lines-1) * lines)
                 / (1024.0*1024.0));
    double MB_per_sec =  MB / elapsed;
    cout << "MB/sec " << MB_per_sec << " MB " << MB
         << " elapsed time " << elapsed
         << endl;
    return rc;
}
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;
}
int ocvm_maximum_spanning_tree2::process(void)
{
    std::cout << "ocvm_maximum_spanning_tree2: running on "
              << dcmpi_get_hostname() << "\n";

    int subimage_width = get_param_as_int("subimage_width");
    int subimage_height = get_param_as_int("subimage_height");
    double subimage_overlap = Atof(get_param("subimage_overlap"));

    int i;
    int4 nXChunks, nYChunks;
    nXChunks = get_param_as_int("nXChunks");
    nYChunks = get_param_as_int("nYChunks");
    int4 score, x_displacement, y_displacement, x_ref, y_ref,
        x_subject, y_subject, left_to_right, diffX, diffY;
    std::cout << "ocvm_maximum_spanning_tree2: " << nXChunks
              << "x" << nYChunks << " image coming at me\n";

//     GlobalAligner ga = GlobalAligner(nXChunks, nYChunks, subimage_width, subimage_height, subimage_overlap/100.0);
    GlobalAligner ga = GlobalAligner(nXChunks, nYChunks);
    int num_incoming_packets =
        ((nXChunks-1) * nYChunks) +
        ((nYChunks-1) * nXChunks);
    std::cout << "ocvm_maximum_spanning_tree2: num_incoming_packets is "
              << num_incoming_packets << endl;

    for (i = 0; i < num_incoming_packets; i++) {
        DCBuffer * in = read("from_aligners");
        in->Extract(&score);
        in->Extract(&x_displacement);
        in->Extract(&y_displacement);
        in->Extract(&x_ref);
        in->Extract(&y_ref);
        in->Extract(&x_subject);
        in->Extract(&y_subject);
        in->Extract(&left_to_right);
        in->Extract(&diffX);
        in->Extract(&diffY);

//         std::cout << "maximum_spanning_tree2: next packet: "
//                   << score << " " << x_displacement << " " << y_displacement
//                   << " (" << x_ref << "," << y_ref
//                   << ") (" << x_subject  << "," << y_subject
//                   << ") " << left_to_right
//                   << " " << diffX << " " << diffY << "\n";
        
        int edge_index;
        if (left_to_right) {
//	   edge_index = (nYChunks - y_ref - 1)*(2*nXChunks - 1);
            edge_index = y_subject*(2*nXChunks - 1);
            if (y_subject == nYChunks-1) 
                edge_index = edge_index + x_ref;
            else
                edge_index = edge_index + 2*x_ref + 1;
            ga.init_edge(edge_index, x_displacement, y_displacement, score);
        }
        else {
            edge_index = y_ref*(2*nXChunks - 1) + 2*x_subject;
            ga.init_edge(edge_index, -1*x_displacement, -1*y_displacement, score);
        }
//	std::cout << "edge index= " << edge_index << std::endl;
        
        in->consume();
    }

    double before = dcmpi_doubletime();
    std::cout << "w: " << subimage_width << endl;
    std::cout << "h: " << subimage_height << endl;
    std::cout << "o: " << subimage_overlap << endl;
    ga.init_tiles((int8)(subimage_width * (1.0 - (subimage_overlap / 100.0))),
                  (int8)(subimage_height * (1.0 - (subimage_overlap / 100.0))));
//    ga.displayEdges();

//    std::cout << std::endl;
//    ga.displayOffsets();
//    std::cout << std::endl;
    ga.calculateDisplacements();
    std::cout << std::endl;
    ga.normalizeOffsets(); 
//    ga.displayOffsets();
    ga.finalizeOffsets();
//    ga.displayOffsets();
    std::cout << std::endl;

    double elapsed = dcmpi_doubletime() - before;
    DCBuffer *outb = new DCBuffer(8 + (((nXChunks * nYChunks * 2) + 2) * sizeof(int8)));
    std::cout << "spanning tree took this many seconds: " << elapsed <<endl;
    outb->Append(ga.maxX+subimage_width);
    outb->Append(ga.maxY+subimage_height);
    for (i = 0; i < nXChunks*nYChunks; i++) {
        outb->Append(ga.tiles[i]->offsetX);
        outb->Append(ga.tiles[i]->offsetY);
    }
    write_nocopy(outb, "to_console");

    std::cout << "f-mst.cpp: exiting\n";
    return 0;
}