File: insert_task_cache.c

package info (click to toggle)
starpu-contrib 1.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: contrib
  • in suites: wheezy
  • size: 13,836 kB
  • sloc: ansic: 77,357; cpp: 23,334; sh: 12,088; makefile: 2,086; lisp: 758; yacc: 185; sed: 126; fortran: 13
file content (145 lines) | stat: -rw-r--r-- 4,901 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* StarPU --- Runtime system for heterogeneous multicore architectures.
 *
 * Copyright (C) 2011, 2012  Centre National de la Recherche Scientifique
 *
 * StarPU is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at
 * your option) any later version.
 *
 * StarPU is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * See the GNU Lesser General Public License in COPYING.LGPL for more details.
 */

#include <starpu_mpi.h>
#include <math.h>
#include "helper.h"

void func_cpu(void *descr[], __attribute__ ((unused)) void *_args)
{
	unsigned *x = (unsigned *)STARPU_VARIABLE_GET_PTR(descr[0]);
	unsigned *y = (unsigned *)STARPU_VARIABLE_GET_PTR(descr[1]);

        FPRINTF(stdout, "VALUES: %d %d\n", *x, *y);
        *x = (*x + *y) / 2;
}

struct starpu_codelet mycodelet =
{
	.where = STARPU_CPU,
	.cpu_funcs = {func_cpu, NULL},
        .nbuffers = 2,
	.modes = {STARPU_RW, STARPU_R}
};

#define X     4
#define Y     5

/* Returns the MPI node number where data indexes index is */
int my_distrib(int x, int y, int nb_nodes)
{
        return x % nb_nodes;
}


int main(int argc, char **argv)
{
        int rank, size, x, y;
        int ret,value=0;
        unsigned matrix[X][Y];
        starpu_data_handle_t data_handles[X][Y];

	ret = starpu_init(NULL);
	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
	ret = starpu_mpi_initialize_extended(&rank, &size);
	STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_initialize_extended");

        for(x = 0; x < X; x++)
	{
                for (y = 0; y < Y; y++)
		{
                        matrix[x][y] = (rank+1)*10 + value;
                        value++;
                }
        }
#if 0
        for(x = 0; x < X; x++)
	{
                FPRINTF(stdout, "[%d] ", rank);
                for (y = 0; y < Y; y++)
		{
                        FPRINTF(stdout, "%3d ", matrix[x][y]);
                }
                FPRINTF(stdout, "\n");
        }
#endif

        for(x = 0; x < X; x++)
	{
                for (y = 0; y < Y; y++)
		{
                        int mpi_rank = my_distrib(x, y, size);
                        if (mpi_rank == rank)
			{
                                //FPRINTF(stderr, "[%d] Owning data[%d][%d]\n", rank, x, y);
                                starpu_variable_data_register(&data_handles[x][y], 0, (uintptr_t)&(matrix[x][y]), sizeof(unsigned));
                        }
                        else if (rank == mpi_rank+1 || rank == mpi_rank-1)
			{
                                /* I don't own that index, but will need it for my computations */
                                //FPRINTF(stderr, "[%d] Neighbour of data[%d][%d]\n", rank, x, y);
                                starpu_variable_data_register(&data_handles[x][y], -1, (uintptr_t)NULL, sizeof(unsigned));
                        }
                        else
			{
                                /* I know it's useless to allocate anything for this */
                                data_handles[x][y] = NULL;
                        }
                        if (data_handles[x][y])
			{
                                starpu_data_set_rank(data_handles[x][y], mpi_rank);
                                starpu_data_set_tag(data_handles[x][y], (y*X)+x);
			}
                }
        }

        ret = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handles[1][1], STARPU_R, data_handles[0][1], 0);
	STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_insert_task");
        ret = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handles[3][1], STARPU_R, data_handles[0][1], 0);
	STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_insert_task");
        ret = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handles[0][1], STARPU_R, data_handles[0][0], 0);
	STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_insert_task");
        ret = starpu_mpi_insert_task(MPI_COMM_WORLD, &mycodelet, STARPU_RW, data_handles[3][1], STARPU_R, data_handles[0][1], 0);
	STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_insert_task");

        FPRINTF(stderr, "Waiting ...\n");
        starpu_task_wait_for_all();

        for(x = 0; x < X; x++)
	{
                for (y = 0; y < Y; y++)
		{
                        if (data_handles[x][y])
                                starpu_data_unregister(data_handles[x][y]);
                }
        }
	starpu_mpi_shutdown();
	starpu_shutdown();

#if 0
        for(x = 0; x < X; x++)
	{
                FPRINTF(stdout, "[%d] ", rank);
                for (y = 0; y < Y; y++)
		{
                        FPRINTF(stdout, "%3d ", matrix[x][y]);
                }
                FPRINTF(stdout, "\n");
        }
#endif

	return 0;
}