Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
| charm [2012/01/05 16:31] – [Exemple : HelloWorld] admin | charm [2012/01/05 16:36] (Version actuelle) – [Exemple : HelloWorld] admin | ||
|---|---|---|---|
| Ligne 15: | Ligne 15: | ||
| ======Exemple : HelloWorld ====== | ======Exemple : HelloWorld ====== | ||
| - | ** Interface**\\ | + | {{: |
| - | <file C hello.c> | + | |
| - | module hello { | + | |
| - | array [1D] Hello { | + | ===== Exemple |
| - | entry Hello(); | + | |
| - | entry void sayHi(int); | + | |
| - | }; | + | |
| - | + | ||
| - | }; | + | |
| - | </ | + | |
| - | + | ||
| - | **Header file**\\ | + | |
| - | <file C hello.h> | + | |
| - | + | ||
| - | #ifndef __HELLO_H__ | + | |
| - | #define __HELLO_H__ | + | |
| - | + | ||
| - | class Hello : public CBase_Hello { | + | |
| - | + | ||
| - | | + | |
| - | + | ||
| - | /// Constructors /// | + | |
| - | Hello(); | + | |
| - | Hello(CkMigrateMessage *msg); | + | |
| - | + | ||
| - | /// Entry Methods /// | + | |
| - | void sayHi(int from); | + | |
| - | }; | + | |
| - | + | ||
| - | #endif // | + | |
| - | </ | + | |
| - | + | ||
| - | <file C hello.C> | + | |
| - | #include " | + | |
| - | + | ||
| - | #include " | + | |
| - | #include " | + | |
| - | + | ||
| - | extern /* readonly */ CProxy_Main mainProxy; | + | |
| - | extern /* readonly */ int numElements; | + | |
| - | + | ||
| - | Hello:: | + | |
| - | // Nothing to do when the Hello chare object is created. | + | |
| - | // This is where member variables would be initialized | + | |
| - | // just like in a C++ class constructor. | + | |
| - | } | + | |
| - | + | ||
| - | // Constructor needed for chare object migration (ignore for now) | + | |
| - | // NOTE: This constructor does not need to appear in the " | + | |
| - | Hello:: | + | |
| - | + | ||
| - | void Hello ::sayHi(int from) { | + | |
| - | + | ||
| - | // Have this chare object say hello to the user. | + | |
| - | CkPrintf(" | + | |
| - | " | + | |
| - | | + | |
| - | + | ||
| - | // Tell the next chare object in this array of chare objects | + | |
| - | // to also say hello. If this is the last chare object in | + | |
| - | // the array of chare objects, then tell the main chare | + | |
| - | // object to exit the program. | + | |
| - | if (thisIndex < (numElements - 1)) | + | |
| - | thisProxy[thisIndex + 1].sayHi(thisIndex); | + | |
| - | else | + | |
| - | mainProxy.done(); | + | |
| - | } | + | |
| - | + | ||
| - | #include " | + | |
| - | </ | + | |
| + | <code bash> | ||
| + | $ charmrun +p3 ./hello 10 | ||
| + | Running "Hello World" with 10 elements using 3 processors. | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | </ | ||
| ======Liens | ======Liens | ||
| http:// | http:// | ||