コード例 #1
0
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;
}
コード例 #2
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;
}