/* * Wait for termination */ void wait_end_tasks(int rank) { int bz; int nbz = get_nbz(); for (bz = 0; bz < nbz; bz++) { if (get_block_mpi_node(bz) == rank) { /* Wait for the task producing block "bz" */ starpu_tag_wait(TAG_FINISH(bz)); /* Get the result back to memory */ struct block_description *block = get_block_description(bz); starpu_data_acquire(block->layers_handle[0], STARPU_R); starpu_data_acquire(block->layers_handle[1], STARPU_R); /* the data_acquire here is done to make sure * the data is sent back to the ram memory, we * can safely do a data_release, to avoid the * data_unregister to block later on */ starpu_data_release(block->layers_handle[0]); starpu_data_release(block->layers_handle[1]); } } }
int main(int argc, char **argv) { int ret; ret = starpu_initialize(NULL, &argc, &argv); if (ret == -ENODEV) return STARPU_TEST_SKIPPED; STARPU_CHECK_RETURN_VALUE(ret, "starpu_init"); starpu_malloc((void**)&data, sizeof(*data)); *data = 42; /* register a piece of data */ starpu_vector_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)data, 1, sizeof(unsigned)); struct starpu_task *task = starpu_task_create(); task->cl = &wrong_codelet; task->handles[0] = handle; task->use_tag = 1; task->tag_id = TAG; task->callback_func = wrong_callback; task->detach = 0; ret = starpu_task_submit(task); if (ret == -ENODEV) goto enodev; STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit"); ret = starpu_tag_wait(TAG); STARPU_CHECK_RETURN_VALUE(ret, "starpu_tag_wait"); /* This call is valid as it is done by the application outside a * callback */ ret = starpu_data_acquire(handle, STARPU_RW); STARPU_CHECK_RETURN_VALUE(ret, "starpu_data_acquire"); starpu_data_release(handle); ret = starpu_task_wait(task); STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait"); starpu_data_unregister(handle); starpu_free(data); starpu_shutdown(); return EXIT_SUCCESS; enodev: fprintf(stderr, "WARNING: No one can execute this task\n"); /* yes, we do not perform the computation but we did detect that no one * could perform the kernel, so this is not an error from StarPU */ starpu_shutdown(); return STARPU_TEST_SKIPPED; }
static void callback_sync_data(void *arg) { struct data *data = (struct data *) arg; data->val++; starpu_data_release(data->handle); }
int main(int argc, char **argv) { int ret, rank, size; starpu_data_handle_t handle; int var; MPI_Init(&argc, &argv); starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank); starpu_mpi_comm_size(MPI_COMM_WORLD, &size); ret = starpu_init(NULL); STARPU_CHECK_RETURN_VALUE(ret, "starpu_init"); ret = starpu_mpi_init(NULL, NULL, 0); STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init"); if (size<3) { FPRINTF(stderr, "We need more than 2 processes.\n"); starpu_mpi_shutdown(); starpu_shutdown(); MPI_Finalize(); return STARPU_TEST_SKIPPED; } if (rank == 0) { int n; for(n=1 ; n<size ; n++) { MPI_Status status; FPRINTF_MPI(stderr, "receiving from node %d\n", n); starpu_variable_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)&var, sizeof(var)); starpu_mpi_recv(handle, n, 42, MPI_COMM_WORLD, &status); starpu_data_acquire(handle, STARPU_R); STARPU_ASSERT_MSG(var == n, "Received incorrect value <%d> from node <%d>\n", var, n); FPRINTF_MPI(stderr, "received <%d> from node %d\n", var, n); starpu_data_release(handle); starpu_data_unregister(handle); } } else { FPRINTF_MPI(stderr, "sending to node %d\n", 0); var = rank; starpu_variable_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)&var, sizeof(var)); starpu_mpi_send(handle, 0, 42, MPI_COMM_WORLD); starpu_data_unregister(handle); } starpu_mpi_shutdown(); starpu_shutdown(); MPI_Finalize(); return 0; }
int main(int argc, char **argv) { starpu_init(NULL); /* Allocate all buffers and register them to StarPU */ unsigned b; for (b = 0; b < NBUFFERS; b++) { starpu_data_malloc_pinned_if_possible((void **)&buffer[b], VECTORSIZE); starpu_vector_data_register(&v_handle[b], 0, (uintptr_t)buffer[b], VECTORSIZE, sizeof(char)); } unsigned iter; for (iter = 0; iter < NITER; iter++) { /* Use the buffers on the different workers so that it may not * be in main memory anymore */ for (b = 0; b < NBUFFERS; b++) use_handle(v_handle[b]); starpu_task_wait_for_all(); /* Grab the different pieces of data into main memory */ for (b = 0; b < NBUFFERS; b++) starpu_data_acquire(v_handle[b], STARPU_RW); /* Release them */ for (b = 0; b < NBUFFERS; b++) starpu_data_release(v_handle[b]); } /* do some cleanup */ for (b = 0; b < NBUFFERS; b++) starpu_data_unregister(v_handle[b]); starpu_shutdown(); return 0; }
int main(int argc, char **argv) { int i, j, ret; ret = starpu_initialize(NULL, &argc, &argv); if (ret == -ENODEV) return STARPU_TEST_SKIPPED; STARPU_CHECK_RETURN_VALUE(ret, "starpu_initialize"); float *data; starpu_malloc((void**)&data, sizeof(*data) * NB_BUNDLE); float factors[NB_BUNDLE]; starpu_data_handle_t handles[NB_BUNDLE]; struct starpu_task *task[NB_ITERATION]; starpu_task_bundle_t bundles[NB_BUNDLE]; for (i = 0; i < NB_BUNDLE; i++) { data[i] = i + 1; factors[i] = NB_BUNDLE - i; } for (i = 0; i < NB_BUNDLE; i++) starpu_variable_data_register(&handles[i], STARPU_MAIN_RAM, (uintptr_t)&data[i], sizeof(float)); FPRINTF(stderr, "VALUES:"); for (i = 0; i < NB_BUNDLE; i++) FPRINTF(stderr, " %f (%f)", data[i], factors[i]); FPRINTF(stderr, "\n"); for (i = 0; i < NB_BUNDLE; i++) { starpu_task_bundle_create(&bundles[i]); for (j = 0; j < NB_ITERATION; j++) { task[j] = starpu_task_create(); task[j]->cl = &codelet; task[j]->cl_arg = &factors[i]; task[j]->cl_arg_size = sizeof(float); task[j]->handles[0] = handles[i]; ret = starpu_task_bundle_insert(bundles[i], task[j]); STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert"); } ret = starpu_task_bundle_remove(bundles[i], task[NB_ITERATION / 2]); STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_remove"); for (j = 0; j < NB_ITERATION; j++) { ret = starpu_task_submit(task[j]); if (ret == -ENODEV) goto enodev; STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit"); } starpu_task_bundle_close(bundles[i]); } ret = starpu_task_wait_for_all(); STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all"); for(i = 0; i < NB_BUNDLE ; i++) { ret = starpu_data_acquire(handles[i], STARPU_R); STARPU_CHECK_RETURN_VALUE(ret, "starpu_data_acquire"); } FPRINTF(stderr, "VALUES:"); for (i = 0; i < NB_BUNDLE; i++) FPRINTF(stderr, " %f (%f)", data[i], factors[i]); FPRINTF(stderr, "\n"); for(i = 0; i < NB_BUNDLE ; i++) { starpu_data_release(handles[i]); starpu_data_unregister(handles[i]); } starpu_free(data); starpu_shutdown(); return EXIT_SUCCESS; enodev: starpu_shutdown(); fprintf(stderr, "WARNING: No one can execute this task\n"); /* yes, we do not perform the computation but we did detect that no one * could perform the kernel, so this is not an error from StarPU */ return STARPU_TEST_SKIPPED; }
int main(int argc, char **argv) { int ret; #ifdef STARPU_QUICK_CHECK nbuffers /= 4; niter /= 4; vectorsize /= 8; #endif ret = starpu_initialize(NULL, &argc, &argv); if (ret == -ENODEV) return STARPU_TEST_SKIPPED; STARPU_CHECK_RETURN_VALUE(ret, "starpu_init"); /* Allocate all buffers and register them to StarPU */ int b; for (b = 0; b < nbuffers; b++) { ret = starpu_malloc((void **)&buffer[b], vectorsize); STARPU_CHECK_RETURN_VALUE(ret, "starpu_malloc"); starpu_vector_data_register(&v_handle[b], STARPU_MAIN_RAM, (uintptr_t)buffer[b], vectorsize, sizeof(char)); } int iter; for (iter = 0; iter < niter; iter++) { /* Use the buffers on the different workers so that it may not * be in main memory anymore */ for (b = 0; b < nbuffers; b++) { ret = use_handle(v_handle[b]); if (ret == -ENODEV) goto enodev; STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit"); } ret = starpu_task_wait_for_all(); STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all"); /* Grab the different pieces of data into main memory */ for (b = 0; b < nbuffers; b++) { ret = starpu_data_acquire(v_handle[b], STARPU_RW); STARPU_CHECK_RETURN_VALUE(ret, "starpu_data_acquire"); } /* Release them */ for (b = 0; b < nbuffers; b++) starpu_data_release(v_handle[b]); } /* do some cleanup */ for (b = 0; b < nbuffers; b++) { starpu_data_unregister(v_handle[b]); starpu_free(buffer[b]); } starpu_shutdown(); return EXIT_SUCCESS; enodev: fprintf(stderr, "WARNING: No one can execute this task\n"); /* yes, we do not perform the computation but we did detect that no one * could perform the kernel, so this is not an error from StarPU */ starpu_shutdown(); return STARPU_TEST_SKIPPED; }
int main(int argc, char **argv) { unsigned i; float foo; starpu_data_handle float_array_handle; starpu_codelet cl; starpu_init(NULL); if (argc == 2) niter = atoi(argv[1]); foo = 0.0f; starpu_variable_data_register(&float_array_handle, 0 /* home node */, (uintptr_t)&foo, sizeof(float)); #ifdef STARPU_USE_OPENCL starpu_opencl_load_opencl_from_file("examples/basic_examples/variable_kernels_opencl_codelet.cl", &opencl_code); #endif cl.where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL; cl.cpu_func = cpu_codelet; #ifdef STARPU_USE_CUDA cl.cuda_func = cuda_codelet; #endif #ifdef STARPU_USE_OPENCL cl.opencl_func = opencl_codelet; #endif cl.nbuffers = 1; cl.model = NULL; for (i = 0; i < niter; i++) { struct starpu_task *task = starpu_task_create(); int ret; task->cl = &cl; task->callback_func = NULL; task->buffers[0].handle = float_array_handle; task->buffers[0].mode = STARPU_RW; ret = starpu_task_submit(task, NULL); if (STARPU_UNLIKELY(ret == -ENODEV)) { fprintf(stderr, "No worker may execute this task\n"); exit(0); } } starpu_task_wait_for_all(); /* update the array in RAM */ starpu_data_acquire(float_array_handle, STARPU_R); fprintf(stderr, "variable -> %f\n", foo); starpu_data_release(float_array_handle); starpu_shutdown(); return 0; }
int main(int argc, char **argv) { int ret, rank, size; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); if (size<3) { FPRINTF(stderr, "We need more than 2 processes.\n"); MPI_Finalize(); return STARPU_TEST_SKIPPED; } ret = starpu_init(NULL); STARPU_CHECK_RETURN_VALUE(ret, "starpu_init"); ret = starpu_mpi_init(NULL, NULL, 0); STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init"); if (rank == 0) { int n; for(n=1 ; n<size ; n++) { int i, var[2]; MPI_Status status[3]; starpu_data_handle_t handle[2]; FPRINTF_MPI(stderr, "receiving from node %d\n", n); for(i=0 ; i<2 ; i++) starpu_variable_data_register(&handle[i], STARPU_MAIN_RAM, (uintptr_t)&var[i], sizeof(var[i])); starpu_mpi_recv(handle[0], n, 42, MPI_COMM_WORLD, &status[0]); starpu_data_acquire(handle[0], STARPU_R); STARPU_ASSERT_MSG(var[0] == n, "Received incorrect value <%d> from node <%d>\n", var[0], n); FPRINTF_MPI(stderr, "received <%d> from node %d\n", var[0], n); starpu_data_release(handle[0]); starpu_mpi_recv(handle[0], n, 42, MPI_COMM_WORLD, &status[1]); starpu_mpi_recv(handle[1], n, 44, MPI_COMM_WORLD, &status[2]); for(i=0 ; i<2 ; i++) starpu_data_acquire(handle[i], STARPU_R); STARPU_ASSERT_MSG(var[0] == n*2, "Received incorrect value <%d> from node <%d>\n", var[0], n); STARPU_ASSERT_MSG(var[1] == n*4, "Received incorrect value <%d> from node <%d>\n", var[0], n); FPRINTF_MPI(stderr, "received <%d> and <%d> from node %d\n", var[0], var[1], n); for(i=0 ; i<2 ; i++) starpu_data_release(handle[i]); for(i=0 ; i<2 ; i++) starpu_data_unregister(handle[i]); } } else { int i, var[3]; starpu_data_handle_t handle[3]; FPRINTF_MPI(stderr, "sending to node %d\n", 0); var[0] = rank; var[1] = var[0] * 2; var[2] = var[0] * 4; for(i=0 ; i<3 ; i++) starpu_variable_data_register(&handle[i], STARPU_MAIN_RAM, (uintptr_t)&var[i], sizeof(var[i])); starpu_mpi_send(handle[0], 0, 42, MPI_COMM_WORLD); starpu_mpi_send(handle[1], 0, 42, MPI_COMM_WORLD); starpu_mpi_send(handle[2], 0, 44, MPI_COMM_WORLD); for(i=0 ; i<3 ; i++) starpu_data_unregister(handle[i]); } starpu_mpi_shutdown(); starpu_shutdown(); MPI_Finalize(); return 0; }
int do_test(int rank, int sdetached, int rdetached) { int ret, i; int val[2]; starpu_data_handle_t data[2]; ret = starpu_init(NULL); STARPU_CHECK_RETURN_VALUE(ret, "starpu_init"); ret = starpu_mpi_init(NULL, NULL, 0); STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init"); if (rank == 1) { val[0] = VAL0; val[1] = VAL1; } else { val[0] = -1; val[1] = -1; } starpu_variable_data_register(&data[0], STARPU_MAIN_RAM, (uintptr_t)&val[0], sizeof(val[0])); starpu_variable_data_register(&data[1], STARPU_MAIN_RAM, (uintptr_t)&val[1], sizeof(val[1])); starpu_mpi_data_register(data[0], 77, 1); starpu_mpi_data_register(data[1], 88, 1); if (rank == 1) { for(i=1 ; i>=0 ; i--) { if (sdetached) starpu_mpi_isend_detached(data[i], 0, starpu_data_get_tag(data[i]), MPI_COMM_WORLD, NULL, NULL); else starpu_mpi_send(data[i], 0, starpu_data_get_tag(data[i]), MPI_COMM_WORLD); } } else if (rank == 0) { int received = 0; for(i=0 ; i<2 ; i++) FPRINTF_MPI(stderr, "Value[%d] = %d\n", i, val[i]); for(i=0 ; i<2 ; i++) { if (rdetached) starpu_mpi_irecv_detached(data[i], 1, starpu_data_get_tag(data[i]), MPI_COMM_WORLD, callback, &received); else starpu_mpi_recv(data[i], 1, starpu_data_get_tag(data[i]), MPI_COMM_WORLD, MPI_STATUS_IGNORE); } if (rdetached) { STARPU_PTHREAD_MUTEX_LOCK(&mutex); while (received != 2) { FPRINTF_MPI(stderr, "Received %d messages\n", received); STARPU_PTHREAD_COND_WAIT(&cond, &mutex); } STARPU_PTHREAD_MUTEX_UNLOCK(&mutex); } for(i=0 ; i<2 ; i++) starpu_data_acquire(data[i], STARPU_R); for(i=0 ; i<2 ; i++) FPRINTF_MPI(stderr, "Value[%d] = %d\n", i, val[i]); for(i=0 ; i<2 ; i++) starpu_data_release(data[i]); } FPRINTF_MPI(stderr, "Waiting ...\n"); starpu_task_wait_for_all(); starpu_data_unregister(data[0]); starpu_data_unregister(data[1]); if (rank == 0) { ret = (val[0] == VAL0 && val[1] == VAL1) ? 0 : 1; } starpu_mpi_shutdown(); starpu_shutdown(); return ret; }
int main(int argc, char **argv) { int ret, rank, size; ret = starpu_init(NULL); STARPU_CHECK_RETURN_VALUE(ret, "starpu_init"); ret = starpu_mpi_init(NULL, NULL, 1); STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init"); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); if (size < 2) { if (rank == 0) FPRINTF(stderr, "We need at least 2 processes.\n"); MPI_Finalize(); return STARPU_TEST_SKIPPED; } starpu_vector_data_register(&token_handle, STARPU_MAIN_RAM, (uintptr_t)&token, 1, sizeof(token)); int nloops = NITER; int loop; int last_loop = nloops - 1; int last_rank = size - 1; for (loop = 0; loop < nloops; loop++) { int tag = loop*size + rank; if (loop == 0 && rank == 0) { token = 0; FPRINTF(stdout, "Start with token value %u\n", token); } else { starpu_mpi_irecv_detached(token_handle, (rank+size-1)%size, tag, MPI_COMM_WORLD, NULL, NULL); } increment_token(); if (loop == last_loop && rank == last_rank) { starpu_data_acquire(token_handle, STARPU_R); FPRINTF(stdout, "Finished : token value %u\n", token); starpu_data_release(token_handle); } else { starpu_mpi_isend_detached(token_handle, (rank+1)%size, tag+1, MPI_COMM_WORLD, NULL, NULL); } } starpu_task_wait_for_all(); starpu_data_unregister(token_handle); starpu_mpi_shutdown(); starpu_shutdown(); if (rank == last_rank) { FPRINTF(stderr, "[%d] token = %u == %u * %d ?\n", rank, token, nloops, size); STARPU_ASSERT(token == nloops*size); } return 0; }
int main(int argc, char **argv) { int rank, size, err; int x[2]; int ret, i; starpu_data_handle_t data_handles[2]; int values[2]; ret = starpu_init(NULL); STARPU_CHECK_RETURN_VALUE(ret, "starpu_init"); ret = starpu_mpi_init(&argc, &argv, 1); STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init"); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); if (rank == 0) { x[0] = 11; starpu_variable_data_register(&data_handles[0], STARPU_MAIN_RAM, (uintptr_t)&x[0], sizeof(x[0])); starpu_variable_data_register(&data_handles[1], -1, (uintptr_t)NULL, sizeof(x[1])); } else if (rank == 1) { x[1] = 12; starpu_variable_data_register(&data_handles[0], -1, (uintptr_t)NULL, sizeof(x[0])); starpu_variable_data_register(&data_handles[1], STARPU_MAIN_RAM, (uintptr_t)&x[1], sizeof(x[1])); } else { starpu_variable_data_register(&data_handles[0], -1, (uintptr_t)NULL, sizeof(x[0])); starpu_variable_data_register(&data_handles[1], -1, (uintptr_t)NULL, sizeof(x[1])); } starpu_mpi_data_register(data_handles[0], 0, 0); starpu_mpi_data_register(data_handles[1], 1, 1); err = starpu_mpi_task_insert(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handles[0], STARPU_RW, data_handles[1], STARPU_EXECUTE_ON_DATA, data_handles[1], 0); assert(err == 0); starpu_task_wait_for_all(); for(i=0 ; i<2 ; i++) { starpu_mpi_get_data_on_node_detached(MPI_COMM_WORLD, data_handles[i], 0, NULL, NULL); if (rank == 0) { starpu_data_acquire(data_handles[i], STARPU_R); values[i] = *((int *)starpu_data_get_local_ptr(data_handles[i])); starpu_data_release(data_handles[i]); } } ret = 0; if (rank == 0) { FPRINTF(stderr, "[%d][local ptr] VALUES: %d %d\n", rank, values[0], values[1]); if (values[0] != 12 || values[1] != 144) { ret = EXIT_FAILURE; } } starpu_data_unregister(data_handles[0]); starpu_data_unregister(data_handles[1]); starpu_mpi_shutdown(); starpu_shutdown(); return ret; }
int main(int argc, char **argv) { int size, x; int color; MPI_Comm newcomm; int rank, newrank; int ret; starpu_data_handle_t data[3]; int value = 90; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); if (size < 4) { FPRINTF(stderr, "We need at least 4 processes.\n"); MPI_Finalize(); return STARPU_TEST_SKIPPED; } color = rank%2; MPI_Comm_split(MPI_COMM_WORLD, color, rank, &newcomm); MPI_Comm_rank(newcomm, &newrank); FPRINTF(stderr, "[%d][%d] color %d\n", rank, newrank, color); if (newrank == 0) { FPRINTF(stderr, "[%d][%d] sending %d\n", rank, newrank, rank); MPI_Send(&rank, 1, MPI_INT, 1, 10, newcomm); } else if (newrank == 1) { MPI_Recv(&x, 1, MPI_INT, 0, 10, newcomm, MPI_STATUS_IGNORE); FPRINTF(stderr, "[%d][%d] received %d\n", rank, newrank, x); } ret = starpu_init(NULL); STARPU_CHECK_RETURN_VALUE(ret, "starpu_init"); ret = starpu_mpi_init(NULL, NULL, 0); STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init"); if (rank == 0) { starpu_variable_data_register(&data[2], STARPU_MAIN_RAM, (uintptr_t)&value, sizeof(int)); } else starpu_variable_data_register(&data[2], -1, (uintptr_t)NULL, sizeof(int)); starpu_mpi_data_register_comm(data[2], 44, 0, MPI_COMM_WORLD); if (newrank == 0) { starpu_variable_data_register(&data[0], STARPU_MAIN_RAM, (uintptr_t)&rank, sizeof(int)); starpu_variable_data_register(&data[1], STARPU_MAIN_RAM, (uintptr_t)&rank, sizeof(int)); starpu_mpi_data_register_comm(data[1], 22, 0, newcomm); } else starpu_variable_data_register(&data[0], -1, (uintptr_t)NULL, sizeof(int)); starpu_mpi_data_register_comm(data[0], 12, 0, newcomm); if (newrank == 0) { starpu_mpi_req req[2]; starpu_mpi_issend(data[1], &req[0], 1, 22, newcomm); starpu_mpi_isend(data[0], &req[1], 1, 12, newcomm); starpu_mpi_wait(&req[0], MPI_STATUS_IGNORE); starpu_mpi_wait(&req[1], MPI_STATUS_IGNORE); } else if (newrank == 1) { int *xx; starpu_mpi_recv(data[0], 0, 12, newcomm, MPI_STATUS_IGNORE); starpu_data_acquire(data[0], STARPU_RW); xx = (int *)starpu_variable_get_local_ptr(data[0]); starpu_data_release(data[0]); FPRINTF(stderr, "[%d][%d] received %d\n", rank, newrank, *xx); STARPU_ASSERT_MSG(x==*xx, "Received value %d is incorrect (should be %d)\n", *xx, x); starpu_variable_data_register(&data[1], -1, (uintptr_t)NULL, sizeof(int)); starpu_mpi_data_register_comm(data[1], 22, 0, newcomm); starpu_mpi_recv(data[0], 0, 22, newcomm, MPI_STATUS_IGNORE); starpu_data_acquire(data[0], STARPU_RW); xx = (int *)starpu_variable_get_local_ptr(data[0]); starpu_data_release(data[0]); FPRINTF(stderr, "[%d][%d] received %d\n", rank, newrank, *xx); STARPU_ASSERT_MSG(x==*xx, "Received value %d is incorrect (should be %d)\n", *xx, x); } if (rank == 0) { starpu_data_acquire(data[2], STARPU_RW); int rvalue = *((int *)starpu_variable_get_local_ptr(data[2])); starpu_data_release(data[2]); FPRINTF_MPI(stderr, "sending value %d to %d and receiving from %d\n", rvalue, 1, size-1); starpu_mpi_send(data[2], 1, 44, MPI_COMM_WORLD); starpu_mpi_recv(data[2], size-1, 44, MPI_COMM_WORLD, MPI_STATUS_IGNORE); starpu_data_acquire(data[2], STARPU_RW); int *xx = (int *)starpu_variable_get_local_ptr(data[2]); starpu_data_release(data[2]); FPRINTF_MPI(stderr, "Value back is %d\n", *xx); STARPU_ASSERT_MSG(*xx == rvalue + (2*(size-1)), "Received value %d is incorrect (should be %d)\n", *xx, rvalue + (2*(size-1))); } else { int next = (rank == size-1) ? 0 : rank+1; starpu_mpi_recv(data[2], rank-1, 44, MPI_COMM_WORLD, MPI_STATUS_IGNORE); starpu_data_acquire(data[2], STARPU_RW); int *xx = (int *)starpu_variable_get_local_ptr(data[2]); FPRINTF_MPI(stderr, "receiving %d from %d and sending %d to %d\n", *xx, rank-1, *xx+2, next); *xx = *xx + 2; starpu_data_release(data[2]); starpu_mpi_send(data[2], next, 44, MPI_COMM_WORLD); } if (newrank == 0 || newrank == 1) { starpu_mpi_insert_task(newcomm, &mycodelet, STARPU_RW, data[0], STARPU_VALUE, &x, sizeof(x), STARPU_EXECUTE_ON_NODE, 1, 0); starpu_task_wait_for_all(); starpu_data_unregister(data[0]); starpu_data_unregister(data[1]); } starpu_data_unregister(data[2]); starpu_mpi_shutdown(); starpu_shutdown(); MPI_Comm_free(&newcomm); MPI_Finalize(); return 0; }
int main(int argc, char **argv) { MPI_Init(NULL, NULL); int rank, size; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); if (size < 2) { if (rank == 0) fprintf(stderr, "We need at least processes.\n"); MPI_Finalize(); return 0; } /* We only use 2 nodes for that test */ if (rank >= 2) { MPI_Finalize(); return 0; } starpu_init(NULL); starpu_mpi_initialize(); /* Node 0 will allocate a big block and only register an inner part of * it as the block data, Node 1 will allocate a block of small size and * register it directly. Node 0 and 1 will then exchange the content of * their blocks. */ float *block; starpu_data_handle block_handle; if (rank == 0) { block = calloc(BIGSIZE*BIGSIZE*BIGSIZE, sizeof(float)); assert(block); /* fill the inner block */ unsigned i, j, k; for (k = 0; k < SIZE; k++) for (j = 0; j < SIZE; j++) for (i = 0; i < SIZE; i++) { block[i + j*BIGSIZE + k*BIGSIZE*BIGSIZE] = 1.0f; } starpu_block_data_register(&block_handle, 0, (uintptr_t)block, BIGSIZE, BIGSIZE*BIGSIZE, SIZE, SIZE, SIZE, sizeof(float)); } else /* rank == 1 */ { block = calloc(SIZE*SIZE*SIZE, sizeof(float)); assert(block); starpu_block_data_register(&block_handle, 0, (uintptr_t)block, SIZE, SIZE*SIZE, SIZE, SIZE, SIZE, sizeof(float)); } if (rank == 0) { starpu_mpi_send(block_handle, 1, 0x42, MPI_COMM_WORLD); MPI_Status status; starpu_mpi_recv(block_handle, 1, 0x1337, MPI_COMM_WORLD, &status); /* check the content of the block */ starpu_data_acquire(block_handle, STARPU_R); unsigned i, j, k; for (k = 0; k < SIZE; k++) for (j = 0; j < SIZE; j++) for (i = 0; i < SIZE; i++) { assert(block[i + j*BIGSIZE + k*BIGSIZE*BIGSIZE] == 33.0f); } starpu_data_release(block_handle); } else /* rank == 1 */ { MPI_Status status; starpu_mpi_recv(block_handle, 0, 0x42, MPI_COMM_WORLD, &status); /* check the content of the block and modify it */ starpu_data_acquire(block_handle, STARPU_RW); unsigned i, j, k; for (k = 0; k < SIZE; k++) for (j = 0; j < SIZE; j++) for (i = 0; i < SIZE; i++) { assert(block[i + j*SIZE + k*SIZE*SIZE] == 1.0f); block[i + j*SIZE + k*SIZE*SIZE] = 33.0f; } starpu_data_release(block_handle); starpu_mpi_send(block_handle, 0, 0x1337, MPI_COMM_WORLD); } fprintf(stdout, "Rank %d is done\n", rank); fflush(stdout); starpu_mpi_shutdown(); starpu_shutdown(); MPI_Finalize(); return 0; }