Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
    int provided;
    MPI_Request request;
    int flag;
    int outcount = -1;
    int indices[1] = { -1 };
    MPI_Status status;
    char *env;

    env = getenv("MPITEST_VERBOSE");
    if (env) {
        if (*env != '0')
            verbose = 1;
    }

    MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided);
    if (provided != MPI_THREAD_MULTIPLE) {
        printf("This test requires MPI_THREAD_MULTIPLE\n");
        MPI_Abort(MPI_COMM_WORLD, 1);
    }

    IF_VERBOSE(("Post Init ...\n"));

    MPI_Grequest_start(query_fn, free_fn, cancel_fn, NULL, &request);
    grequest = request; /* copy the handle */
    MTest_Start_thread(do_work, &grequest);
    IF_VERBOSE(("Testing ...\n"));
    flag = 0;
    while (!flag) {
        MPI_Test(&request, &flag, &status);
    }
    MTest_Join_threads();

    MPI_Grequest_start(query_fn, free_fn, cancel_fn, NULL, &request);
    grequest = request; /* copy the handle */
    MTest_Start_thread(do_work, &grequest);
    IF_VERBOSE(("Testing ...\n"));
    outcount = 0;
    while (!outcount) {
        MPI_Testsome(1, &request, &outcount, indices, &status);
    }
    MTest_Join_threads();

    MPI_Grequest_start(query_fn, free_fn, cancel_fn, NULL, &request);
    grequest = request; /* copy the handle */
    MTest_Start_thread(do_work, &grequest);
    IF_VERBOSE(("Testing ...\n"));
    flag = 0;
    while (!flag) {
        MPI_Testall(1, &request, &flag, &status);
    }
    MTest_Join_threads();

    IF_VERBOSE(("Goodbye !!!\n"));
    MTest_Finalize(0);
    MPI_Finalize();
    return 0;
}
Ejemplo n.º 2
0
MTEST_THREAD_RETURN_TYPE do_work(void *arg)
{
  MPI_Request *req = (MPI_Request *)arg;
  IF_VERBOSE(("Starting work in thread ...\n"));
  MTestSleep(3);
  IF_VERBOSE(("Work in thread done !!!\n"));
  MPI_Grequest_complete(*req);
  return MTEST_THREAD_RETVAL_IGN;
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
    int error;
    int rank, size;
    char *argv1[2] = { (char*)"connector", NULL };
    char *argv2[2] = { (char*)"acceptor", NULL };
    MPI_Comm comm_connector, comm_acceptor, comm_parent, comm;
    char port[MPI_MAX_PORT_NAME];
    MPI_Status status;
    MPI_Info spawn_path = MPI_INFO_NULL;
    int verbose = 0;

    if (getenv("MPITEST_VERBOSE"))
    {
	verbose = 1;
    }

    IF_VERBOSE(("init.\n"));
    error = MPI_Init(&argc, &argv);
    check_error(error, "MPI_Init");

    /* To improve reporting of problems about operations, we
       change the error handler to errors return */
    MPI_Comm_set_errhandler( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
    MPI_Comm_set_errhandler( MPI_COMM_SELF, MPI_ERRORS_RETURN );

    IF_VERBOSE(("size.\n"));
    error = MPI_Comm_size(MPI_COMM_WORLD, &size);
    check_error(error, "MPI_Comm_size");

    IF_VERBOSE(("rank.\n"));
    error = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    check_error(error, "MPI_Comm_rank");

    if (argc == 1)
    {
	/* Make sure that the current directory is in the path.
	   Not all implementations may honor or understand this, but
	   it is highly recommended as it gives users a clean way
	   to specify the location of the executable without
	   specifying a particular directory format (e.g., this 
	   should work with both Windows and Unix implementations) */
	error = MPI_Info_create( &spawn_path );
	check_error( error, "MPI_Info_create" );
	error = MPI_Info_set( spawn_path, (char*)"path", (char*)"." );
	check_error( error, "MPI_Info_set" );

	IF_VERBOSE(("spawn connector.\n"));
	error = MPI_Comm_spawn((char*)"spaconacc", argv1, 1, spawn_path, 0, 
			       MPI_COMM_SELF, &comm_connector, 
			       MPI_ERRCODES_IGNORE);
	check_error(error, "MPI_Comm_spawn");

	IF_VERBOSE(("spawn acceptor.\n"));
	error = MPI_Comm_spawn((char*)"spaconacc", argv2, 1, spawn_path, 0, 
			       MPI_COMM_SELF, &comm_acceptor, 
			       MPI_ERRCODES_IGNORE);
	check_error(error, "MPI_Comm_spawn");
	error = MPI_Info_free( &spawn_path );
	check_error( error, "MPI_Info_free" );

	MPI_Comm_set_errhandler( comm_connector, MPI_ERRORS_RETURN );
	MPI_Comm_set_errhandler( comm_acceptor, MPI_ERRORS_RETURN );

	IF_VERBOSE(("recv port.\n"));
	error = MPI_Recv(port, MPI_MAX_PORT_NAME, MPI_CHAR, 0, 0, 
			 comm_acceptor, &status);
	check_error(error, "MPI_Recv");

	IF_VERBOSE(("send port.\n"));
	error = MPI_Send(port, MPI_MAX_PORT_NAME, MPI_CHAR, 0, 0, 
			 comm_connector);
	check_error(error, "MPI_Send");

	IF_VERBOSE(("barrier acceptor.\n"));
	error = MPI_Barrier(comm_acceptor);
	check_error(error, "MPI_Barrier");

	IF_VERBOSE(("barrier connector.\n"));
	error = MPI_Barrier(comm_connector);
	check_error(error, "MPI_Barrier");

        error = MPI_Comm_free(&comm_acceptor);
	check_error(error, "MPI_Comm_free");
        error = MPI_Comm_free(&comm_connector);
	check_error(error, "MPI_Comm_free");

	printf(" No Errors\n");
    }
    else if ((argc == 2) && (strcmp(argv[1], "acceptor") == 0))
    {
	IF_VERBOSE(("get_parent.\n"));
	error = MPI_Comm_get_parent(&comm_parent);
	check_error(error, "MPI_Comm_get_parent");
	if (comm_parent == MPI_COMM_NULL)
	{
	    printf("acceptor's parent is NULL.\n");fflush(stdout);
	    MPI_Abort(MPI_COMM_WORLD, -1);
	}
	IF_VERBOSE(("open_port.\n"));
	error = MPI_Open_port(MPI_INFO_NULL, port);
	check_error(error, "MPI_Open_port");

	MPI_Comm_set_errhandler( comm_parent, MPI_ERRORS_RETURN );

	IF_VERBOSE(("0: opened port: <%s>\n", port));
	IF_VERBOSE(("send.\n"));
	error = MPI_Send(port, MPI_MAX_PORT_NAME, MPI_CHAR, 0, 0, comm_parent);
	check_error(error, "MPI_Send");

	IF_VERBOSE(("accept.\n"));
	error = MPI_Comm_accept(port, MPI_INFO_NULL, 0, MPI_COMM_SELF, &comm);
	check_error(error, "MPI_Comm_accept");

	IF_VERBOSE(("close_port.\n"));
	error = MPI_Close_port(port);
	check_error(error, "MPI_Close_port");

	IF_VERBOSE(("disconnect.\n"));
	error = MPI_Comm_disconnect(&comm);
	check_error(error, "MPI_Comm_disconnect");

	IF_VERBOSE(("barrier.\n"));
	error = MPI_Barrier(comm_parent);
	check_error(error, "MPI_Barrier");

	MPI_Comm_free( &comm_parent );
    }
    else if ((argc == 2) && (strcmp(argv[1], "connector") == 0))
    {
	IF_VERBOSE(("get_parent.\n"));
	error = MPI_Comm_get_parent(&comm_parent);
	check_error(error, "MPI_Comm_get_parent");
	if (comm_parent == MPI_COMM_NULL)
	{
	    printf("acceptor's parent is NULL.\n");fflush(stdout);
	    MPI_Abort(MPI_COMM_WORLD, -1);
	}

	MPI_Comm_set_errhandler( comm_parent, MPI_ERRORS_RETURN );
	IF_VERBOSE(("recv.\n"));
	error = MPI_Recv(port, MPI_MAX_PORT_NAME, MPI_CHAR, 0, 0, 
			 comm_parent, &status);
	check_error(error, "MPI_Recv");

	IF_VERBOSE(("1: received port: <%s>\n", port));
	IF_VERBOSE(("connect.\n"));
	error = MPI_Comm_connect(port, MPI_INFO_NULL, 0, MPI_COMM_SELF, &comm);
	check_error(error, "MPI_Comm_connect");

	MPI_Comm_set_errhandler( comm, MPI_ERRORS_RETURN );
	IF_VERBOSE(("disconnect.\n"));
	error = MPI_Comm_disconnect(&comm);
	check_error(error, "MPI_Comm_disconnect");

	IF_VERBOSE(("barrier.\n"));
	error = MPI_Barrier(comm_parent);
	check_error(error, "MPI_Barrier");

	MPI_Comm_free( &comm_parent );
    }
    else
    {
	printf("invalid command line.\n");fflush(stdout);
	{
	    int i;
	    for (i=0; i<argc; i++)
	    {
		printf("argv[%d] = <%s>\n", i, argv[i]);
	    }
	}
	fflush(stdout);
	MPI_Abort(MPI_COMM_WORLD, -2);
    }

    MPI_Finalize();
    return 0;
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
    int errs = 0;
    int rank, size, rsize;
    int np = 3;
    MPI_Comm parentcomm, intercomm;
    int verbose = 0;
    char *env;
    int can_spawn;

    env = getenv("MPITEST_VERBOSE");
    if (env) {
        if (*env != '0')
            verbose = 1;
    }

    MTest_Init(&argc, &argv);

    errs += MTestSpawnPossible(&can_spawn);

    if (can_spawn) {
        MPI_Comm_get_parent(&parentcomm);

        if (parentcomm == MPI_COMM_NULL) {
            IF_VERBOSE(("spawning %d processes\n", np));
            /* Create 3 more processes */
            MPI_Comm_spawn((char *) "./disconnect", MPI_ARGV_NULL, np,
                           MPI_INFO_NULL, 0, MPI_COMM_WORLD, &intercomm, MPI_ERRCODES_IGNORE);
        } else {
            intercomm = parentcomm;
        }

        /* We now have a valid intercomm */

        MPI_Comm_remote_size(intercomm, &rsize);
        MPI_Comm_size(intercomm, &size);
        MPI_Comm_rank(intercomm, &rank);

        if (parentcomm == MPI_COMM_NULL) {
            IF_VERBOSE(("parent rank %d alive.\n", rank));
            /* Parent */
            if (rsize != np) {
                errs++;
                printf("Did not create %d processes (got %d)\n", np, rsize);
                fflush(stdout);
            }
            IF_VERBOSE(("disconnecting child communicator\n"));
            MPI_Comm_disconnect(&intercomm);

            /* Errors cannot be sent back to the parent because there is no
             * communicator connected to the children
             * for (i=0; i<rsize; i++)
             * {
             * MPI_Recv(&err, 1, MPI_INT, i, 1, intercomm, MPI_STATUS_IGNORE);
             * errs += err;
             * }
             */
        } else {
            IF_VERBOSE(("child rank %d alive.\n", rank));
            /* Child */
            if (size != np) {
                errs++;
                printf("(Child) Did not create %d processes (got %d)\n", np, size);
                fflush(stdout);
            }

            IF_VERBOSE(("disconnecting communicator\n"));
            MPI_Comm_disconnect(&intercomm);

            /* Send the errs back to the master process */
            /* Errors cannot be sent back to the parent because there is no
             * communicator connected to the parent */
            /*MPI_Ssend(&errs, 1, MPI_INT, 0, 1, intercomm); */
        }

        /* Note that the MTest_Finalize get errs only over COMM_WORLD */
        /* Note also that both the parent and child will generate "No Errors"
         * if both call MTest_Finalize */
        if (parentcomm == MPI_COMM_NULL) {
            MTest_Finalize(errs);
        } else {
            MPI_Finalize();
        }
    } else {
        MTest_Finalize(errs);
    }

    IF_VERBOSE(("calling finalize\n"));
    return MTestReturnValue(errs);
}
Ejemplo n.º 5
0
/* This test spawns two child jobs and has them open a port and connect to
 * each other.
 * The two children repeatedly connect, accept, and disconnect from each other.
 */
int main(int argc, char *argv[])
{
    int error;
    int rank, size;
    int numprocs = 3;
    char *argv1[2] = { (char *) "connector", NULL };
    char *argv2[2] = { (char *) "acceptor", NULL };
    MPI_Comm comm_connector, comm_acceptor, comm_parent, comm;
    char port[MPI_MAX_PORT_NAME] = { 0 };
    MPI_Status status;
    MPI_Info spawn_path = MPI_INFO_NULL;
    int i, num_loops = 100;
    int data;
    int verbose = 0;
    int can_spawn, errs = 0;

    if (getenv("MPITEST_VERBOSE")) {
        verbose = 1;
    }

    IF_VERBOSE(("init.\n"));
    error = MPI_Init(&argc, &argv);
    check_error(error, "MPI_Init");

    errs += MTestSpawnPossible(&can_spawn);
    if (!can_spawn) {
        if (errs)
            printf(" Found %d errors\n", errs);
        else
            printf(" No Errors\n");
        fflush(stdout);
    } else {
        IF_VERBOSE(("size.\n"));
        error = MPI_Comm_size(MPI_COMM_WORLD, &size);
        check_error(error, "MPI_Comm_size");

        IF_VERBOSE(("rank.\n"));
        error = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
        check_error(error, "MPI_Comm_rank");

        if (argc == 1) {
            /* Make sure that the current directory is in the path.
             * Not all implementations may honor or understand this, but
             * it is highly recommended as it gives users a clean way
             * to specify the location of the executable without
             * specifying a particular directory format (e.g., this
             * should work with both Windows and Unix implementations) */
            MPI_Info_create(&spawn_path);
            MPI_Info_set(spawn_path, (char *) "path", (char *) ".");

            IF_VERBOSE(("spawn connector.\n"));
            error = MPI_Comm_spawn((char *) "disconnect_reconnect2",
                                   argv1, numprocs, spawn_path, 0,
                                   MPI_COMM_WORLD, &comm_connector, MPI_ERRCODES_IGNORE);
            check_error(error, "MPI_Comm_spawn");

            IF_VERBOSE(("spawn acceptor.\n"));
            error = MPI_Comm_spawn((char *) "disconnect_reconnect2",
                                   argv2, numprocs, spawn_path, 0,
                                   MPI_COMM_WORLD, &comm_acceptor, MPI_ERRCODES_IGNORE);
            check_error(error, "MPI_Comm_spawn");
            MPI_Info_free(&spawn_path);

            if (rank == 0) {
                IF_VERBOSE(("recv port.\n"));
                error = MPI_Recv(port, MPI_MAX_PORT_NAME, MPI_CHAR, 0, 0, comm_acceptor, &status);
                check_error(error, "MPI_Recv");

                IF_VERBOSE(("send port.\n"));
                error = MPI_Send(port, MPI_MAX_PORT_NAME, MPI_CHAR, 0, 0, comm_connector);
                check_error(error, "MPI_Send");
            }

            IF_VERBOSE(("barrier acceptor.\n"));
            error = MPI_Barrier(comm_acceptor);
            check_error(error, "MPI_Barrier");

            IF_VERBOSE(("barrier connector.\n"));
            error = MPI_Barrier(comm_connector);
            check_error(error, "MPI_Barrier");

            error = MPI_Comm_free(&comm_acceptor);
            check_error(error, "MPI_Comm_free");
            error = MPI_Comm_free(&comm_connector);
            check_error(error, "MPI_Comm_free");

            if (rank == 0) {
                printf(" No Errors\n");
                fflush(stdout);
            }
        } else if ((argc == 2) && (strcmp(argv[1], "acceptor") == 0)) {
            IF_VERBOSE(("get_parent.\n"));
            error = MPI_Comm_get_parent(&comm_parent);
            check_error(error, "MPI_Comm_get_parent");
            if (comm_parent == MPI_COMM_NULL) {
                printf("acceptor's parent is NULL.\n");
                fflush(stdout);
                MPI_Abort(MPI_COMM_WORLD, -1);
            }
            if (rank == 0) {
                IF_VERBOSE(("open_port.\n"));
                error = MPI_Open_port(MPI_INFO_NULL, port);
                check_error(error, "MPI_Open_port");

                IF_VERBOSE(("0: opened port: <%s>\n", port));
                IF_VERBOSE(("send.\n"));
                error = MPI_Send(port, MPI_MAX_PORT_NAME, MPI_CHAR, 0, 0, comm_parent);
                check_error(error, "MPI_Send");
            }

            for (i = 0; i < num_loops; i++) {
                IF_VERBOSE(("accept.\n"));
                error = MPI_Comm_accept(port, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &comm);
                check_error(error, "MPI_Comm_accept");

                if (rank == 0) {
                    data = i;
                    error = MPI_Send(&data, 1, MPI_INT, 0, 0, comm);
                    check_error(error, "MPI_Send");
                    error = MPI_Recv(&data, 1, MPI_INT, 0, 0, comm, &status);
                    check_error(error, "MPI_Recv");
                    if (data != i) {
                        printf("expected %d but received %d\n", i, data);
                        fflush(stdout);
                        MPI_Abort(MPI_COMM_WORLD, 1);
                    }
                }

                IF_VERBOSE(("disconnect.\n"));
                error = MPI_Comm_disconnect(&comm);
                check_error(error, "MPI_Comm_disconnect");
            }

            if (rank == 0) {
                IF_VERBOSE(("close_port.\n"));
                error = MPI_Close_port(port);
                check_error(error, "MPI_Close_port");
            }

            IF_VERBOSE(("barrier.\n"));
            error = MPI_Barrier(comm_parent);
            check_error(error, "MPI_Barrier");

            MPI_Comm_free(&comm_parent);
        } else if ((argc == 2) && (strcmp(argv[1], "connector") == 0)) {
            IF_VERBOSE(("get_parent.\n"));
            error = MPI_Comm_get_parent(&comm_parent);
            check_error(error, "MPI_Comm_get_parent");
            if (comm_parent == MPI_COMM_NULL) {
                printf("acceptor's parent is NULL.\n");
                fflush(stdout);
                MPI_Abort(MPI_COMM_WORLD, -1);
            }

            if (rank == 0) {
                IF_VERBOSE(("recv.\n"));
                error = MPI_Recv(port, MPI_MAX_PORT_NAME, MPI_CHAR, 0, 0, comm_parent, &status);
                check_error(error, "MPI_Recv");
                IF_VERBOSE(("1: received port: <%s>\n", port));
            }

            for (i = 0; i < num_loops; i++) {
                IF_VERBOSE(("connect.\n"));
                error = MPI_Comm_connect(port, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &comm);
                check_error(error, "MPI_Comm_connect");

                if (rank == 0) {
                    data = -1;
                    error = MPI_Recv(&data, 1, MPI_INT, 0, 0, comm, &status);
                    check_error(error, "MPI_Recv");
                    if (data != i) {
                        printf("expected %d but received %d\n", i, data);
                        fflush(stdout);
                        MPI_Abort(MPI_COMM_WORLD, 1);
                    }
                    error = MPI_Send(&data, 1, MPI_INT, 0, 0, comm);
                    check_error(error, "MPI_Send");
                }

                IF_VERBOSE(("disconnect.\n"));
                error = MPI_Comm_disconnect(&comm);
                check_error(error, "MPI_Comm_disconnect");
            }

            IF_VERBOSE(("barrier.\n"));
            error = MPI_Barrier(comm_parent);
            check_error(error, "MPI_Barrier");

            MPI_Comm_free(&comm_parent);
        } else {
            printf("invalid command line.\n");
            fflush(stdout);
            {
                int ii;
                for (ii = 0; ii < argc; ii++) {
                    printf("argv[%d] = <%s>\n", ii, argv[ii]);
                }
            }
            fflush(stdout);
            MPI_Abort(MPI_COMM_WORLD, -2);
        }
    }

    MPI_Finalize();
    return MTestReturnValue(errs);
}
Ejemplo n.º 6
0
int main(int argc, char *argv[])
{
    int errs = 0;
    int child_errs = 0;
    int size, rsize, i, num_spawns = 0;
    char description[100];
    char child_spawns[10];
    char *argv1[3] = { child_spawns, description, NULL };
    MPI_Comm parentcomm, intercomm[MAX_NUM_SPAWNS];
    MPI_Status status;
    int verbose = 0;
    char *env;
    int can_spawn;

    env = getenv("MPITEST_VERBOSE");
    if (env) {
        if (*env != '0')
            verbose = 1;
    }

    MTest_Init(&argc, &argv);

    errs += MTestSpawnPossible(&can_spawn);

    if (can_spawn) {
        /* Set the num_spawns for the first process to MAX_NUM_SPAWNS */
        MPI_Comm_get_parent(&parentcomm);
        if (parentcomm == MPI_COMM_NULL) {
            num_spawns = MAX_NUM_SPAWNS;
        }

        /* If an argument is passed in use it for num_spawns */
        /* This is the case for all spawned processes and optionally the first
         * process as well */
        if (argc > 1) {
            num_spawns = atoi(argv[1]);
            if (num_spawns < 0)
                num_spawns = 0;
            if (num_spawns > MAX_NUM_SPAWNS)
                num_spawns = MAX_NUM_SPAWNS;
        }

        /* Send num_spawns - 1 on the command line to the spawned children */
        sprintf(child_spawns, "%d", num_spawns - 1 > 0 ? num_spawns - 1 : 0);

        /* Spawn the children */
        IF_VERBOSE(("spawning %d\n", num_spawns));
        for (i = 0; i < num_spawns; i++) {
            if (argc > 2) {
                sprintf(description, "%s:%d", argv[2], i);
            } else {
                sprintf(description, "%d", i);
            }
            IF_VERBOSE(("spawning %s\n", description));
            MPI_Comm_spawn((char *) "./concurrent_spawns", argv1, 1,
                           MPI_INFO_NULL, 0, MPI_COMM_WORLD, &intercomm[i], MPI_ERRCODES_IGNORE);

            MPI_Comm_remote_size(intercomm[i], &rsize);
            MPI_Comm_size(intercomm[i], &size);
            if (rsize != 1) {
                errs++;
                printf("Did not create 1 process (got %d)\n", rsize);
                fflush(stdout);
            }
        }

        /* Receive the error count from each of your children and add it to your
         * error count */
        for (i = 0; i < num_spawns; i++) {
            MPI_Recv(&child_errs, 1, MPI_INT, 0, 0, intercomm[i], &status);
            errs += child_errs;
            MPI_Comm_disconnect(&intercomm[i]);
        }

        /* If you are a spawned process send your errors to your parent */
        if (parentcomm != MPI_COMM_NULL) {
            MPI_Send(&errs, 1, MPI_INT, 0, 0, parentcomm);
            MPI_Comm_disconnect(&parentcomm);
            MPI_Finalize();
        } else {
            /* Note that the MTest_Finalize get errs only over COMM_WORLD */
            /* Note also that both the parent and child will generate "No Errors"
             * if both call MTest_Finalize */
            MTest_Finalize(errs);
        }
    } else {
        MTest_Finalize(errs);
    }

    IF_VERBOSE(("calling finalize\n"));
    return MTestReturnValue(errs);
}
Ejemplo n.º 7
0
	static window_regression_stats *get_window_regression_stats(
	 const grid<pixel_t> &red, const grid<pixel_t> &nir, size_t size,
	 bool force)
	{
		size_t output_block = 100;
		size_t row_count = (red.height() / size);
		IF_NORMAL(std::cout << row_count << " rows" << std::endl);
		size_t window_count = (red.width() / size) * row_count;
		array<numeric_t> slopes(window_count);
		array<numeric_t> intercepts(window_count);
		array<numeric_t> r2s(window_count);
		array<bool> goodness(window_count);
		numeric_t *slopes_ptr = slopes.data();
		numeric_t *intercepts_ptr = intercepts.data();
		numeric_t *r2s_ptr = r2s.data();
		bool *ptr_goodness = goodness.data();
		size_t good_count = 0;
		rect<size_t> subr = {0, 0, size, size};
		for (subr.y = 0; subr.y + size <= red.height() && subr.y +
		 size <= nir.height(); subr.y += size) {
			for (subr.x = 0; subr.x + size <= red.width() &&
			 subr.x + size <= nir.width(); subr.x += size) {
				const grid<pixel_t> red_sub(
				 const_cast<grid<pixel_t>*>(&red), subr);
				const grid<pixel_t> nir_sub(
				 const_cast<grid<pixel_t>*>(&nir), subr);
				if (force || is_good_data(red_sub, nir_sub)) {
					linear_regression *reg =
					 stats_find_linear_regression(red_sub,
					 nir_sub);
					*slopes_ptr = reg->eq.slope;
					*intercepts_ptr = reg->eq.intercept;
					*r2s_ptr = reg->r2;
					*ptr_goodness = true;
					good_count++;
					delete reg;
				} else {
					IF_VERBOSE(std::cout << "Bad sector: ");
					IF_VERBOSE(std::cout << "(" << subr.x);
					IF_VERBOSE(std::cout << ", " << subr.y);
					IF_VERBOSE(std::cout << ") ");
					*ptr_goodness = false;
				}
				slopes_ptr++;
				intercepts_ptr++;
				r2s_ptr++;
				ptr_goodness++;
			}
			if ((subr.y / size) % output_block == 0) {
				IF_NORMAL(std::cout << "\ranalyzing rows "
				 "starting at " << (subr.y / size) << "...");
				IF_NORMAL(std::cout.flush());
			}
		}
		IF_NORMAL(std::cout << std::endl);
		// okay, we have slope data, now find statistics
		window_regression_stats *stats = new window_regression_stats;
		// first, filter out the bad ones
		IF_VERBOSE(std::cout << "Found " << good_count);
		IF_VERBOSE(std::cout << " good sectors out of ");
		IF_VERBOSE(std::cout << window_count << std::endl);
		array<numeric_t> good_slope_data(good_count);
		array<numeric_t> good_intercept_data(good_count);
		array<numeric_t> good_r2_data(good_count);
		size_t good_data_cur = 0;
		for (size_t i = 0; i < window_count; i++) {
			if (goodness[i]) {
				good_slope_data[good_data_cur] = slopes[i];
				good_intercept_data[good_data_cur] =
				 intercepts[i];
				good_r2_data[good_data_cur] = r2s[i];
				good_data_cur++;
			}
		}
		stats->slope_mean = numeric_mean(good_slope_data);
		stats->slope_stddev = numeric_stddev(good_slope_data);
		stats->intercept_mean = numeric_mean(good_intercept_data);
		stats->intercept_stddev = numeric_stddev(good_intercept_data);
		stats->r2_mean = numeric_mean(good_r2_data);
		stats->r2_stddev = numeric_stddev(good_r2_data);
		stats->window_size = size;
		return stats;
	}
Ejemplo n.º 8
0
	static cell_regression_stats *get_cell_regression_stats(
	 grid<pixel_t> const &red, grid<pixel_t> const &nir, size_t size,
	 bool force)
	{
		size_t output_block = 100;
		rect<size_t> sub = {0, 0, size, size};
		size_t xCount = red.width() / size;
		size_t yCount = red.height() / size;
		IF_NORMAL(std::cout << yCount << " rows" << std::endl);
		size_t cell_count = xCount * yCount;
		array<numeric_t> red_avg(cell_count);
		array<numeric_t> nir_avg(cell_count);
		array<bool> goodness(cell_count);
		size_t good_count = 0;
		bool *goodness_ptr = goodness.data();
		numeric_t *red_avg_ptr = red_avg.data();
		numeric_t *nir_avg_ptr = nir_avg.data();
		for (sub.y = 0; sub.y + size <= red.height(); sub.y += size) {
			for (sub.x = 0; sub.x + size <= red.width();
			 sub.x += size) {
				const grid<pixel_t> sub_red(
				 const_cast<grid<pixel_t>*>(&red), sub);
				const grid<pixel_t> sub_nir(
				 const_cast<grid<pixel_t>*>(&nir), sub);
				if (force || is_good_data(sub_red, sub_nir)) {
					*red_avg_ptr = stats_mean(sub_red);
					*nir_avg_ptr = stats_mean(sub_nir);
					*goodness_ptr = true;
					good_count++;
				} else {
					IF_VERBOSE(std::cout << "Bad sector: ("
					 );
					IF_VERBOSE(std::cout << sub.x << ", ");
					IF_VERBOSE(std::cout << sub.y << ") ");
					*goodness_ptr = false;
				}
				red_avg_ptr++;
				nir_avg_ptr++;
				goodness_ptr++;
			}
			if ((sub.y / size) % output_block == 0) {
				IF_NORMAL(std::cout << "\ranalyzing rows ");
				IF_NORMAL(std::cout << "starting at ");
				IF_NORMAL(std::cout << (sub.y / size));
				IF_NORMAL(std::cout << "...");
				IF_NORMAL(std::cout.flush());
			}
		}
		IF_NORMAL(std::cout << std::endl);
		IF_VERBOSE(std::cout << "Found " << good_count << " good ");
		IF_VERBOSE(std::cout << "sectors out of " << cell_count);
		IF_VERBOSE(std::cout << std::endl);
		array<numeric_t> good_red_data(good_count);
		array<numeric_t> good_nir_data(good_count);
		size_t good_data_cur = 0;
		for (size_t i = 0; i < cell_count; i++) {
			if (goodness[i]) {
				good_red_data[good_data_cur] = red_avg[i];
				good_nir_data[good_data_cur] = nir_avg[i];
				good_data_cur++;
			}
		}
		linear_regression *reg = numeric_find_linear_regression(
		 good_red_data, good_nir_data);
		cell_regression_stats *stats = new cell_regression_stats;
		stats->cell_size = size;
		stats->regression = *reg;
		delete reg;
		return stats;
	}
Ejemplo n.º 9
0
int main( int argc, char *argv[] )
{
    int num_errors = 0, total_num_errors = 0;
    int rank, size;
    char port1[MPI_MAX_PORT_NAME];
    char port2[MPI_MAX_PORT_NAME];
    char port3[MPI_MAX_PORT_NAME];
    MPI_Status status;
    MPI_Comm comm1, comm2, comm3;
    int verbose = 0;
    int data = 0;

    if (getenv("MPITEST_VERBOSE"))
    {
	verbose = 1;
    }

    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    if (size < 4)
    {
	printf("Four processes needed to run this test.\n");
	MPI_Finalize();
	return 0;
    }

    if (rank == 0)
    {
	IF_VERBOSE(("0: opening ports.\n"));
	MPI_Open_port(MPI_INFO_NULL, port1);
	MPI_Open_port(MPI_INFO_NULL, port2);
	MPI_Open_port(MPI_INFO_NULL, port3);

	IF_VERBOSE(("0: opened port1: <%s>\n", port1));
	IF_VERBOSE(("0: opened port2: <%s>\n", port2));
	IF_VERBOSE(("0: opened port3: <%s>\n", port3));
	IF_VERBOSE(("0: sending ports.\n"));
	MPI_Send(port1, MPI_MAX_PORT_NAME, MPI_CHAR, 1, 0, MPI_COMM_WORLD);
	MPI_Send(port2, MPI_MAX_PORT_NAME, MPI_CHAR, 2, 0, MPI_COMM_WORLD);
	MPI_Send(port3, MPI_MAX_PORT_NAME, MPI_CHAR, 3, 0, MPI_COMM_WORLD);

	IF_VERBOSE(("0: accepting port3.\n"));
	MPI_Comm_accept(port3, MPI_INFO_NULL, 0, MPI_COMM_SELF, &comm3);
	IF_VERBOSE(("0: accepting port2.\n"));
	MPI_Comm_accept(port2, MPI_INFO_NULL, 0, MPI_COMM_SELF, &comm2);
	IF_VERBOSE(("0: accepting port1.\n"));
	MPI_Comm_accept(port1, MPI_INFO_NULL, 0, MPI_COMM_SELF, &comm1);

	IF_VERBOSE(("0: closing ports.\n"));
	MPI_Close_port(port1);
	MPI_Close_port(port2);
	MPI_Close_port(port3);

	IF_VERBOSE(("0: sending 1 to process 1.\n"));
	data = 1;
	MPI_Send(&data, 1, MPI_INT, 0, 0, comm1);

	IF_VERBOSE(("0: sending 2 to process 2.\n"));
	data = 2;
	MPI_Send(&data, 1, MPI_INT, 0, 0, comm2);

	IF_VERBOSE(("0: sending 3 to process 3.\n"));
	data = 3;
	MPI_Send(&data, 1, MPI_INT, 0, 0, comm3);

	IF_VERBOSE(("0: disconnecting.\n"));
	MPI_Comm_disconnect(&comm1);
	MPI_Comm_disconnect(&comm2);
	MPI_Comm_disconnect(&comm3);
    }
    else if (rank == 1)
    {
	IF_VERBOSE(("1: receiving port.\n"));
	MPI_Recv(port1, MPI_MAX_PORT_NAME, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &status);

	IF_VERBOSE(("1: received port1: <%s>\n", port1));
	IF_VERBOSE(("1: connecting.\n"));
	MPI_Comm_connect(port1, MPI_INFO_NULL, 0, MPI_COMM_SELF, &comm1);

	MPI_Recv(&data, 1, MPI_INT, 0, 0, comm1, &status);
	if (data != 1)
	{
	    printf("Received %d from root when expecting 1\n", data);
	    fflush(stdout);
	    num_errors++;
	}

	IF_VERBOSE(("1: disconnecting.\n"));
	MPI_Comm_disconnect(&comm1);
    }
    else if (rank == 2)
    {
	IF_VERBOSE(("2: receiving port.\n"));
	MPI_Recv(port2, MPI_MAX_PORT_NAME, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &status);

	IF_VERBOSE(("2: received port2: <%s>\n", port2));
	/* make sure process 1 has time to do the connect before this process 
	   attempts to connect */
	MTestSleep(2);
	IF_VERBOSE(("2: connecting.\n"));
	MPI_Comm_connect(port2, MPI_INFO_NULL, 0, MPI_COMM_SELF, &comm2);

	MPI_Recv(&data, 1, MPI_INT, 0, 0, comm2, &status);
	if (data != 2)
	{
	    printf("Received %d from root when expecting 2\n", data);
	    fflush(stdout);
	    num_errors++;
	}

	IF_VERBOSE(("2: disconnecting.\n"));
	MPI_Comm_disconnect(&comm2);
    }
    else if (rank == 3)
    {
	IF_VERBOSE(("3: receiving port.\n"));
	MPI_Recv(port3, MPI_MAX_PORT_NAME, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &status);

	IF_VERBOSE(("2: received port2: <%s>\n", port2));
	/* make sure process 1 and 2 have time to do the connect before this 
	   process attempts to connect */
	MTestSleep(4);
	IF_VERBOSE(("3: connecting.\n"));
	MPI_Comm_connect(port3, MPI_INFO_NULL, 0, MPI_COMM_SELF, &comm3);

	MPI_Recv(&data, 1, MPI_INT, 0, 0, comm3, &status);
	if (data != 3)
	{
	    printf("Received %d from root when expecting 3\n", data);
	    fflush(stdout);
	    num_errors++;
	}

	IF_VERBOSE(("3: disconnecting.\n"));
	MPI_Comm_disconnect(&comm3);
    }

    MPI_Barrier(MPI_COMM_WORLD);

    MPI_Reduce(&num_errors, &total_num_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
    if (rank == 0)
    {
	if (total_num_errors)
	{
	    printf(" Found %d errors\n", total_num_errors);
	}
	else
	{
	    printf(" No Errors\n");
	}
	fflush(stdout);
    }
    MPI_Finalize();
    return total_num_errors;
}
Ejemplo n.º 10
0
int main(int argc, char *argv[])
{
    int errs = 0;
    int rank, size, rsize, i, data = -1;
    int np = 3;
    MPI_Comm      parentcomm, intercomm;
    MPI_Status    status;
    int verbose = 0;
    char *env;

    env = getenv("MPITEST_VERBOSE");
    if (env)
    {
	if (*env != '0')
	    verbose = 1;
    }

    MTest_Init( &argc, &argv );

    MPI_Comm_get_parent( &parentcomm );

    if (parentcomm == MPI_COMM_NULL)
    {
	IF_VERBOSE(("spawning %d processes\n", np));
	/* Create 3 more processes */
	MPI_Comm_spawn((char*)"./disconnect3", MPI_ARGV_NULL, np,
			MPI_INFO_NULL, 0, MPI_COMM_WORLD,
			&intercomm, MPI_ERRCODES_IGNORE);
    }
    else
    {
	intercomm = parentcomm;
    }

    /* We now have a valid intercomm */

    MPI_Comm_remote_size(intercomm, &rsize);
    MPI_Comm_size(intercomm, &size);
    MPI_Comm_rank(intercomm, &rank);

    if (parentcomm == MPI_COMM_NULL)
    {
	IF_VERBOSE(("parent rank %d alive.\n", rank));
	/* Parent */
	if (rsize != np)
	{
	    errs++;
	    printf("Did not create %d processes (got %d)\n", np, rsize);
	    fflush(stdout);
	}
	if (rank == SENDER_RANK)
	{
	    IF_VERBOSE(("sending int\n"));
	    i = DATA_VALUE;
	    MPI_Send(&i, 1, MPI_INT, RECEIVER_RANK, DATA_TAG, intercomm);
	    MPI_Recv(&data, 1, MPI_INT, RECEIVER_RANK, DATA_TAG, intercomm, 
		     &status);
	    if (data != i)
	    {
		errs++;
	    }
	}
	IF_VERBOSE(("disconnecting child communicator\n"));
	MPI_Comm_disconnect(&intercomm);

	/* Errors cannot be sent back to the parent because there is no 
	   communicator connected to the children
	for (i=0; i<rsize; i++)
	{
	    MPI_Recv( &err, 1, MPI_INT, i, 1, intercomm, MPI_STATUS_IGNORE );
	    errs += err;
	}
	*/
    }
    else
    {
	IF_VERBOSE(("child rank %d alive.\n", rank));
	/* Child */
	if (size != np)
	{
	    errs++;
	    printf("(Child) Did not create %d processes (got %d)\n", np, size);
	    fflush(stdout);
	}

	if (rank == RECEIVER_RANK)
	{
	    IF_VERBOSE(("receiving int\n"));
	    i = -1;
	    MPI_Recv(&i, 1, MPI_INT, SENDER_RANK, DATA_TAG, intercomm, &status);
	    if (i != DATA_VALUE)
	    {
		errs++;
		printf("expected %d but received %d\n", DATA_VALUE, i);
		fflush(stdout);
		MPI_Abort(intercomm, 1);
	    }
	    MPI_Send(&i, 1, MPI_INT, SENDER_RANK, DATA_TAG, intercomm);
	}

	IF_VERBOSE(("disconnecting communicator\n"));
	MPI_Comm_disconnect(&intercomm);

	/* Send the errs back to the master process */
	/* Errors cannot be sent back to the parent because there is no 
	   communicator connected to the parent */
	/*MPI_Ssend( &errs, 1, MPI_INT, 0, 1, intercomm );*/
    }

    /* Note that the MTest_Finalize get errs only over COMM_WORLD */
    /* Note also that both the parent and child will generate "No Errors"
       if both call MTest_Finalize */
    if (parentcomm == MPI_COMM_NULL)
    {
	MTest_Finalize( errs );
    }

    IF_VERBOSE(("calling finalize\n"));
    MPI_Finalize();
    return 0;
}
Ejemplo n.º 11
0
int main(int argc, char *argv[])
{
    int errs = 0;
    int rank, size, rsize, i, j, data, num_loops = 100;
    int np = 3;
    MPI_Comm      parentcomm, intercomm;
    MPI_Status    status;
    char port[MPI_MAX_PORT_NAME] = {0};
    int verbose = 0;
    int do_messages = 1;
    char *env;

    env = getenv("MPITEST_VERBOSE");
    if (env)
    {
	if (*env != '0')
	    verbose = 1;
    }

    MTest_Init( &argc, &argv );

    /* FIXME: Document arguments */
    if (argc > 1) {
	num_loops = atoi(argv[1]);
	if (num_loops < 0)
	    num_loops = 0;
	if (num_loops > 100)
	    num_loops = 100;
    }
    if (argc > 2)
    {
	do_messages = atoi(argv[2]);
    }
    MPI_Comm_get_parent( &parentcomm );

    if (parentcomm == MPI_COMM_NULL)
    {
	MPI_Comm_rank( MPI_COMM_WORLD, &rank ); /* Get rank for verbose msg */
	IF_VERBOSE(("[%d] spawning %d processes\n", rank, np));
	/* Create 3 more processes */
	MPI_Comm_spawn((char*)"./disconnect_reconnect",
			/*MPI_ARGV_NULL*/&argv[1], np,
			MPI_INFO_NULL, 0, MPI_COMM_WORLD,
			&intercomm, MPI_ERRCODES_IGNORE);
    }
    else
    {
	intercomm = parentcomm;
    }

    /* We now have a valid intercomm */

    MPI_Comm_remote_size(intercomm, &rsize);
    MPI_Comm_size(intercomm, &size);
    MPI_Comm_rank(intercomm, &rank);

    if (parentcomm == MPI_COMM_NULL)
    {
	IF_VERBOSE(("[%d] parent rank %d alive.\n", rank, rank));
	/* Parent */
	if (rsize != np)
	{
	    errs++;
	    printf("Did not create %d processes (got %d)\n", np, rsize);
	    fflush(stdout);
	}
	if (rank == 0 && num_loops > 0)
	{
	    MPI_Open_port(MPI_INFO_NULL, port);
	    IF_VERBOSE(("[%d] port = %s\n", rank, port));
	    MPI_Send(port, MPI_MAX_PORT_NAME, MPI_CHAR, 0, 0, intercomm);
	}
	IF_VERBOSE(("[%d] disconnecting child communicator\n",rank));
	MPI_Comm_disconnect(&intercomm);
	for (i=0; i<num_loops; i++)
	{
	    IF_VERBOSE(("[%d] accepting connection\n",rank));
	    MPI_Comm_accept(port, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &intercomm);
	    MPI_Comm_remote_size(intercomm, &rsize);
	    if (do_messages && (rank == 0))
	    {
		j = 0;
		for (j=0; j<rsize; j++)
		{
		    data = i;
		    IF_VERBOSE(("[%d]sending int to child process %d\n", rank, j));
		    MPI_Send(&data, 1, MPI_INT, j, 100, intercomm);
		    IF_VERBOSE(("[%d] receiving int from child process %d\n", rank, j));
		    data = i-1;
		    MPI_Recv(&data, 1, MPI_INT, j, 100, intercomm, &status);
		    if (data != i)
		    {
			errs++;
		    }
		}
	    }
	    IF_VERBOSE(("[%d] disconnecting communicator\n", rank));
	    MPI_Comm_disconnect(&intercomm);
	}

	/* Errors cannot be sent back to the parent because there is no 
	   communicator connected to the children
	for (i=0; i<rsize; i++)
	{
	    MPI_Recv( &err, 1, MPI_INT, i, 1, intercomm, MPI_STATUS_IGNORE );
	    errs += err;
	}
	*/
    }
    else
    {
	IF_VERBOSE(("[%d] child rank %d alive.\n", rank, rank));
	/* Child */
	if (size != np)
	{
	    errs++;
	    printf("(Child) Did not create %d processes (got %d)\n", np, size);
	    fflush(stdout);
	}

	if (rank == 0 && num_loops > 0)
	{
	    IF_VERBOSE(("[%d] receiving port\n", rank));
	    MPI_Recv(port, MPI_MAX_PORT_NAME, MPI_CHAR, 0, 0, intercomm, &status);
	}

	IF_VERBOSE(("[%d] disconnecting communicator\n", rank));
	MPI_Comm_disconnect(&intercomm);
	for (i=0; i<num_loops; i++)
	{
	    IF_VERBOSE(("[%d] connecting to port (loop %d)\n",rank,i));
	    MPI_Comm_connect(port, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &intercomm);
	    if (do_messages)
	    {
		IF_VERBOSE(("[%d] receiving int from parent process 0\n",rank));
		MPI_Recv(&data, 1, MPI_INT, 0, 100, intercomm, &status);
		if (data != i)
		{
		    printf("expected %d but received %d\n", i, data);
		    fflush(stdout);
		    MPI_Abort(MPI_COMM_WORLD, 1);
		}
		IF_VERBOSE(("[%d] sending int back to parent process 1\n",rank));
		MPI_Send(&data, 1, MPI_INT, 0, 100, intercomm);
	    }
	    IF_VERBOSE(("[%d] disconnecting communicator\n",rank));
	    MPI_Comm_disconnect(&intercomm);
	}

	/* Send the errs back to the master process */
	/* Errors cannot be sent back to the parent because there is no 
	   communicator connected to the parent */
	/*MPI_Ssend( &errs, 1, MPI_INT, 0, 1, intercomm );*/
    }

    /* Note that the MTest_Finalize get errs only over COMM_WORLD */
    /* Note also that both the parent and child will generate "No Errors"
       if both call MTest_Finalize */
    if (parentcomm == MPI_COMM_NULL)
    {
	MTest_Finalize( errs );
    }

    IF_VERBOSE(("[%d] calling finalize\n",rank));
    MPI_Finalize();
    return 0;
}