In this tutorial we will learn:
This example has two chare arrays - KeyValueStore and KeyValueClient
Note that even though each client chare knows how many requests it is
making, the keyValueStore element chares do not know how many requests
they will each get.
This could pose some problems in MPI; but its OK
in Charm++. When you contribute into the reduction, the keyValueStore
chares on your processor can continue responding to requests.
Begin with incomplete code below (and can be downloaded here).
/** * * Charm Tutorial Exercise * Key-value store, reduction, sdag * * * **/ mainmodule main { readonly CProxy_Main mainProxy; readonly CProxy_KeyValueStore kvstoreProxy; readonly CProxy_KeyValueClient kvclientProxy; readonly int N; readonly int M; readonly int K; mainchare Main { entry Main(CkArgMsg *m); entry [reductiontarget] void finish(); }; array [1D] KeyValueClient { entry KeyValueClient(); entry void response(int refnum, int value); entry void run(){ serial { for(i=0; i<K; i++){ int key = rand()%(M*N); kvpairs[i].key = key; } } /************ add code here 1. send the request for values for all the keys in the vector kvpairs use method KeyValueStore::request(..) for this 2. the corresponding array elements of KeyValueStore Array will send the values back by calling the KeyValueClient::response(..) that will also have the request refnum. save the value at the correct index (by using refnum) of the kvpairs vector 3. once all the responses have been received, do a reduction with Main::finish() as the reduction target which will exit the program *********/ }; }; array [1D] KeyValueStore { entry KeyValueStore(void); entry void request(int refnum, int k, int reqIdx); }; }; |
The solution can be found here.