========================== Frequently Asked Questions ========================== .. contents:: :depth: 3 For answers to questions not on this list, please create an issue or discussion on our `GitHub `_. Big Questions ============= What is Charm++? ---------------- `Charm++ `_ is a runtime library to let C++ objects communicate with each other efficiently. The programming model is thus an asynchronous message driven paradigm, like Java RMI, or RPC; but it is targeted towards tightly coupled, high-performance parallel machines. Unlike MPI’s "single program, multiple data" (SPMD) programming and execution model, Charm++ programs do not proceed in lockstep. The flow of control is determined by the order in which remote method invocations occur. This can be controlled by the user through Structure Control Flow using :ref:`Structured Dagger `, or `Charisma `_. Charm++ has demonstrated scalability up to hundreds of thousands of processors, and provides extremely advanced load balancing and object migration facilities. Can Charm++ parallelize my serial program automatically? -------------------------------------------------------- No. Charm++ is used to write *explicitly parallel* programs-we don’t have our own compiler, so we don’t do automatic parallelization. We’ve found automatic parallelization useful only for a small range of very regular numerical applications. However, you should *not* have to throw away your serial code; normally only a small fraction of a large program needs to be changed to enable parallel execution. In particular, Charm++’s support for object-oriented programming and high-level abstractions such as Charm++ Arrays make it simpler and more expressive than many other parallel languages. So you will have to write some new code, but not as much as you might think. This is particularly true when using one of the Charm++ `frameworks `_. I can already write parallel applications in MPI. Why should I use Charm++? --------------------------------------------------------------------------- Charm++ provides several extremely sophisticated features, such as application-independent object migration, fault tolerance, power awareness, and automatic overlap of communication with computation, that are very difficult to provide in MPI. If you have a working MPI code but have scalability problems because of dynamic behavior, load imbalance, or communication costs, Charm++ might dramatically improve your performance. You can even run your MPI code on Charm++ unchanged using `AMPI `_. Will Charm++ run on my machine? ------------------------------- Yes. Charm++ supports both shared-memory and distributed-memory machines, SMPs and non-SMPs. In particular, we support serial machines, Windows machines, Apple machines, ARM machines, clusters connected via Ethernet, or Infiniband, IBM Power series, Cray XC/XE/XK series, and any machine that supports MPI. We normally do our development on Linux workstations, and our testing on large parallel machines. Programs written using Charm++ will run on any supported machine. Does anybody actually use Charm++? ---------------------------------- Several large applications use Charm++. - The large, production-quality molecular dynamics application `NAMD `_. - The cosmological simulator `ChaNGa `_. - The atomistic simulation framework `OpenAtom `_. - We have significant collaborations with groups in Materials Science, Chemistry, Astrophysics, Network Simulation, Operation Research, Contagion Effects, in Illinois, New York, California, Washington, and Virginia. See also `Applications `_ for a more complete list. Who created Charm++? -------------------- Prof. `L.V. Kale `_, of the `Computer Science Department `_ of the `University of Illinois at Urbana-Champaign `_, and his research group, the `Parallel Programming Lab `_. Nearly a hundred people have contributed something to the project over the course of approximately 20 years; a partial list of contributors appears on the `people `_ page. What is the future of Charm++? ------------------------------ Our research group of approximately twenty people are actively engaged in maintaining and extending Charm++; and in particular the Charm++ `frameworks `_. Several other groups are dependent on Charm++, so we expect to continue improving Charm++ indefinitely. How is Charm++ Licensed? ------------------------ Charm++ is open-source and free for research, educational, and academic use. The University of Illinois retains the copyright to the software, and requires a license for any commercial redistribution of our software. The actual, legal license is included with Charm++ (in charm/LICENSE). Contact `Charmworks, Inc. `_ for commercial support and licensing of Charm++ and AMPI. I have a suggestion/feature request/bug report. Who should I send it to? ------------------------------------------------------------------------ Please open an issue or discussion on our `GitHub `_. We are always glad to get feedback on our software. Installation and Usage ====================== How do I get Charm++? --------------------- See our `download `_ page. Should I use the GIT version of Charm++? ---------------------------------------- The developers of Charm++ routinely use the latest GIT versions, and most of the time this is the best case. Occasionally something breaks, but the GIT version will likely contain bug fixes not found in the releases. How do I compile Charm++? ------------------------- Run the interactive build script ``./build`` with no extra arguments If this fails, please open an issue on our `GitHub `_ with the problem. Include the build line used (this is saved automatically in ``smart-build.log``) If you have a very unusual machine configuration, you will have to run ``./build -help`` to list all possible build options. You will then choose the closest architecture, and then you may have to modify the associated conf-mach.sh and conv-mach.h files in src/arch to point to your desired compilers and options. If you develop a significantly different platform, please open a pull request on our `GitHub `_ with the modified files so we can include it in the distribution. How do I compile AMPI? ---------------------- Run the build script ``./build`` and choose the option for building "Charm++ and AMPI," or just replace "charm++" in your full build command with "AMPI", as in ``./build AMPI reconverse-linux-x86_64``. Can I remove part of charm tree after compilation to free disk space? --------------------------------------------------------------------- Yes. Keep src, bin, lib, lib_so, include, tmp. You will not need tests, examples, doc, contrib for normal usage once you have verified that your build is functional. If the interactive script fails, how do I compile Charm++? ---------------------------------------------------------- See the Charm manual for :ref:`sec:install`. How do I specify the processors I want to use? ---------------------------------------------- Give the total number of PEs with ``+pe N``. Multiple processes are started with ``lcrun`` on a workstation or with the site's launcher (such as ``srun``) inside a batch allocation; see :ref:`sec:run` of the Charm++ manual. To choose the cores, use the ``+pemap`` option, described in :ref:`sec-smpopts` of the Charm++ manual. Can I use the serial library X from a Charm program? ---------------------------------------------------- Yes. Some of the known working serial libraries include: - The Tcl/Tk interpreter (in NAMD) - The Python interpreter (in Cosmo prototype) - OpenGL graphics (in graphics demos) - Metis mesh partitioning (included with charm) - ATLAS, BLAS, LAPACK, ESSL, FFTW, MASSV, ACML, MKL, BOOST In general, any serial library should work fine with Charm++. How do I get the command-line switches available for a specific program? ------------------------------------------------------------------------ Try .. code-block:: bash ./charmrun ./pgm --help to see a list of parameters at the command line. The charmrun arguments are documented in :ref:`charmrun`. The arguments for the installed libraries are listed in the library manuals. What should I do if my program hangs while gathering CPU topology information at startup? ----------------------------------------------------------------------------------------- This is an indication that your cluster’s DNS server is not responding properly. Ideally, the DNS resolver configured to serve your cluster nodes should be able to rapidly map their hostnames to their IP addresses. As an immediate workaround, you can run your program with the ``+skip_cpu_topology`` flag, at the possible cost of reduced performance. Another workaround is installing and running ``nscd``, the "name service caching daemon", on your cluster nodes; this may add some noise on your systems and hence reduce performance. A third workaround is adding the addresses and names of all cluster nodes in each node’s ``/etc/hosts`` file; this poses maintainability problems for ongoing system administration. Basic Charm++ Programming ========================= What’s the basic programming model for Charm++? ----------------------------------------------- Parallel objects using "Asynchronous Remote Method Invocation": Asynchronous in that you *do not block* until the method returns-the caller continues immediately. Remote in that the two objects may be separated by a network. Method Invocation in that it’s just C++ classes calling each other’s methods. What is an "entry method"? -------------------------- Entry methods are all the methods of a chare where messages can be sent by other chares. They are declared in the .ci files, and they must be defined as public methods of the C++ object representing the chare. When I invoke a remote method, do I block until that method returns? -------------------------------------------------------------------- No! This is one of the biggest differences between Charm++ and most other "remote procedure call" systems like, Java RMI, or RPC. "Invoke an asynchronous method" and "send a message" have exactly the same semantics and implementation. Since the invoking method does not wait for the remote method to terminate, it normally cannot receive any return value. (see later for a way to return values) Why does Charm++ use asynchronous methods? ------------------------------------------ Asynchronous method invocation is more efficient because it can be implemented as a single message send. Unlike with synchronous methods, thread blocking and unblocking and a return message are not needed. Another big advantage of asynchronous methods is that it’s easy to make things run in parallel. If I execute: .. code-block:: c++ a->foo(); b->bar(); Now foo and bar can run at the same time; there’s no reason bar has to wait for foo. Can I make a method synchronous? Can I then return a value? ----------------------------------------------------------- Yes. If you want synchronous methods, so the caller will block, use the ``[sync]`` keyword before the method in the .ci file. This requires the sender to be a threaded entry method, as it will be suspended until the callee finishes. Sync entry methods are allowed to return values to the caller. What is a threaded entry method? How does one make an entry method threaded? ---------------------------------------------------------------------------- A threaded entry method is an entry method for a chare that executes in a separate user-level thread. It is useful when the entry method wants to suspend itself (for example, to wait for more data). Note that threaded entry methods have nothing to do with kernel-level threads or pthreads; they run in user-level threads that are scheduled by Charm++ itself. In order to make an entry method threaded, one should add the keyword *threaded* withing square brackets after the *entry* keyword in the interface file: .. code-block:: charmci module M { chare X { entry [threaded] E1(void); }; }; If I don’t want to use threads, how can an asynchronous method return a value? ------------------------------------------------------------------------------ The usual way to get data back to your caller is via another invocation in the opposite direction: .. code-block:: c++ void A::start(void) { b->giveMeSomeData(); } void B::giveMeSomeData(void) { a->hereIsTheData(data); } void A::hereIsTheData(myclass_t data) { ...use data somehow... } This is contorted, but it exactly matches what the machine has to do. The difficulty of accessing remote data encourages programmers to use local data, bundle outgoing requests, and develop higher-level abstractions, which leads to good performance and good code. Isn’t there a better way to send data back to whoever called me? ---------------------------------------------------------------- The above example is very non-modular, because *b* has to know that *a* called it, and what method to call a back on. For this kind of request/response code, you can abstract away the “where to return the data” with a *CkCallback* object: .. code-block:: c++ void A::start(void) { b->giveMeSomeData(CkCallback(CkIndex_A::hereIsTheData,thisProxy)); } void B::giveMeSomeData(CkCallback returnDataHere) { returnDataHere.send(data); } void A::hereIsTheData(myclass_t data) { ...use data somehow... } Now *b* can be called from several different places in *a*, or from several different modules. Why should I prefer the callback way to return data rather than using ``[sync]`` entry methods? ----------------------------------------------------------------------------------------------- There are a few reasons for that: - The caller needs to be threaded, which implies some overhead in creating the thread. Moreover the threaded entry method will suspend waiting for the data, preventing any code after the remote method invocation to proceed in parallel. - Threaded entry methods are still methods of an object. While they are suspended other entry methods for the same object (or even the same threaded entry method) can be called. This allows for potential problems if the suspending method does leave some objects in an inconsistent state. - Finally, and probably most important, ``[sync]`` entry methods can only be used to return a value that can be computed by a single chare. When more flexibility is needed, such in cases where the resulting value needs to the contribution of multiple objects, the callback methodology is the only one available. The caller could for example send a broadcast to a chare array, which will use a reduction to collect back the results after they have been computed. How does the initialization in Charm work? ------------------------------------------ Each processor executes the following operations strictly in order: #. All methods registered as *initnode*; #. All methods registered as *initproc*; #. On processor zero, all *mainchares* constructor method is invoked (the ones taking a ``CkArgMsg*``); #. The read-onlies are propagated from processor zero to all other processors; #. The nodegroups are created; #. The groups are created. During this phase, for all the chare arrays have been created with a block allocation, the corresponding array elements are instantiated; #. Initialization terminated and all messages are available for processing, including the messages responsible for the instantiation of array elements manually inserted. This implies that you can assume that the previous steps has completely finished before the next one starts, and any side effect from all the previous steps are committed (and can therefore be used). Inside a single step there is no order guarantee. This implies that, for example, two groups allocated from mainchare can be instantiated in any order. The only exception to this is processor zero, where chare objects are instantiated immediately when allocated in the mainchare, i.e if two groups are allocated, their order is fixed by the allocation order in the mainchare constructing them. Again, this is only valid for processor zero, and in no other processor this assumption should be made. To notice that if array elements are allocated in block (by specifying the number of elements at the end of the ``ckNew`` function), they are all instantiated before normal execution is resumed; if manual insertion is used, each element can be constructed at any time on its home processor, and not necessarily before other regular communication messages have been delivered to other chares (including other array elements part of the same array). Does Charm++ support C and Fortran? ----------------------------------- C and Fortran routines can be called from Charm++ using the usual API conventions for accessing them from C++. AMPI supports Fortran directly, but direct use of Charm++ semantics from Fortran is at an immature stage, contact us if you are interested in pursuing this further. What is a proxy? ---------------- A proxy is a local C++ class that represents a remote C++ class. When you invoke a method on a proxy, it sends the request across the network to the real object it represents. In Charm++, all communication is done using proxies. A proxy class for each of your classes is generated based on the methods you list in the .ci file. What are the different ways one can create proxies? --------------------------------------------------- Proxies can be: - Created using ckNew. This is the only method that actually creates a new parallel object. "CProxy_A::ckNew(...)" returns a proxy. - Copied from an existing proxy. This happens when you assign two proxies or send a proxy in a message. - Created from a "handle". This happens when you say "CProxy_A p=thishandle;" - Created uninitialized. This is the default when you say "CProxy_A p;". You’ll get a runtime error "proxy has not been initialized" if you try to use an uninitialized proxy. What is wrong if I do ``A *ap = new CProxy_A(handle)``? ------------------------------------------------------- This will not compile, because a *CProxy_A* is not an *A*. What you want is *CProxy_A \*ap = new CProxy_A(handle)*. Why is the *def.h* usually included at the end? Is it necessary or can I just include it at the beginning? ---------------------------------------------------------------------------------------------------------- You can include the *def.h* file once you’ve actually declared everything it will reference- all your chares and readonly variables. If your chares and readonlies are in your own header files, it is legal to include the *def.h* right away. However, if the class declaration for a chare isn’t visible when you include the *def.h* file, you’ll get a confusing compiler error. This is why we recommend including the *def.h* file at the end. How can I use a global variable across different processors? ------------------------------------------------------------ Make the global variable "readonly" by declaring it in the .ci file. Remember also that read-onlies can be safely set only in the mainchare constructor. Any change after the mainchare constructor has finished will be local to the processor that made the change. To change a global variable later in the program, every processor must modify it accordingly (e.g by using a chare group. Note that chare arrays are not guaranteed to cover all processors) Can I have a class static read-only variable? --------------------------------------------- One can have class-static variables as read-onlies. Inside a chare, group or array declaration in the *.ci* file, one can have a readonly variable declaration. Thus: .. code-block:: charmci chare someChare { ... readonly CkGroupID someGroup; ... }; is fine. In the *.h* declaration for *class someChare*, you will have to put *someGroup* as a public static variable, and you are done. You then refer to the variable in your program as *someChare::someGroup*. How do I measure the time taken by a program or operation? ---------------------------------------------------------- You can use ``CkWallTimer()`` to determine the time on some particular processor. To time some parallel computation, you need to call CkWallTimer on some processor, do the parallel computation, then call CkWallTimer again on the same processor and subtract. What do ``CmiAssert`` and ``CkAssert`` do? ------------------------------------------ These are just like the standard C++ *assert* calls in **- they call abort if the condition passed to them is false. We use our own version rather than the standard version because we have to call *CkAbort*, and because we can turn our asserts off when *--with-production* is used on the build line. These assertions are specifically controlled by *--enable-error-checking* or *--disable-error-checking*. The *--with-production* flag implies *--disable-error-checking*, but it can still be explicitly enabled with *--enable-error-checking*. Can I know how many messages are being sent to a chare? ------------------------------------------------------- No. There is no nice library to solve this problem, as some messages might be queued on the receiving processor, some on the sender, and some on the network. You can still: - Send a return receipt message to the sender, and wait until all the receipts for the messages sent have arrived, then go to a barrier; - Do all the sends, then wait for quiescence. What is "quiescence"? How does it work? --------------------------------------- Quiescence is When nothing is happening anywhere on the parallel machine. A low-level background task counts sent and received messages. When, across the machine, all the messages that have been sent have been received, and nothing is being processed, quiescence is triggered. Should I use quiescence detection? ---------------------------------- Probably not. See the :ref:`sec-completion` section of the manual for instructions on a more local inactivity detection scheme. In some ways, quiescence is a very strong property (it guarantees *nothing* is happening *anywhere*) so if some other library is doing something, you won’t reach quiescence. In other ways, quiescence is a very weak property, since it doesn’t guarantee anything about the state of your application like a reduction does, only that nothing is happening. Because quiescence detection is on the one hand so strong it breaks modularity, and on the other hand is too weak to guarantee anything useful, it’s often better to use something else. Often global properties can be replaced by much easier-to-compute local properties. For example, my object could wait until all *its* neighbors have sent it messages (a local property my object can easily detect by counting message arrivals), rather than waiting until *all* neighbor messages across the whole machine have been sent (a global property that’s difficult to determine). Sometimes a simple reduction is needed instead of quiescence, which has the benefits of being activated explicitly (each element of a chare array or chare group has to call contribute) and allows some data to be collected at the same time. A reduction is also a few times faster than quiescence detection. Finally, there are a few situations, such as some tree-search problems, where quiescence detection is actually the most sensible, efficient solution. Charm++ Arrays ============== How do I know which processor a chare array element is running on? ------------------------------------------------------------------ At any given instant, you can call ``CkMyPe()`` to find out where you are. There is no reliable way to tell where another array element is; even if you could find out at some instant, the element might immediately migrate somewhere else! Should I use Charm++ Arrays in my program? ------------------------------------------ Yes! Most of your computation should happen inside array elements. Arrays are the main way to automatically balance the load using one of the load balancers available. Is there a property similar to ``thisIndex`` containing the chare array’s dimensions or total number of elements? ----------------------------------------------------------------------------------------------------------------- No. In more sophisticated Charm++ algorithms and programs, array dimensions are a dynamic property, and since Charm++ operates in a distributed system context, any such value would potentially be stale between access and use. If the array in question has a fixed size, then that size can be passed to its elements as an argument to their constructor or some later entry method call. Otherwise, the object(s) creating the chare array elements should perform a reduction to count them. How many array elements should I have per processor? ---------------------------------------------------- To do load balancing, you need more than one array element per processor. To keep the time and space overheads reasonable, you probably don’t want more than a few thousand array elements per processor. The optimal value depends on the program, but is usually between 10 and 100. If you come from an MPI background, this may seem like a lot. What does the term reduction refer to? -------------------------------------- You can *reduce* a set of data to a single value. For example, finding the sum of values, where each array element contributes a value to the final sum. Reductions are supported directly by Charm++ arrays, and some operations most commonly used are predefined. Other more complicated reductions can implement if needed. Can I do multiple reductions on an array? ----------------------------------------- You *can* have several reductions happen one after another; but you *cannot* mix up the execution of two reductions over the same array. That is, if you want to reduce A, then B, every array element has to contribute to A, then contribute to B; you cannot have some elements contribute to B, then contribute to A. In addition, *Tuple* reductions provide a way of performing multiple different reductions using the same reduction message. See the :ref:`builtin_reduction` section of the manual for more information on Tuple reductions. Does Charm++ do automatic load balancing without the user asking for it? ------------------------------------------------------------------------ No. You only get load balancing if you explicitly ask for it by linking in one or more load balancers with *-balancer* link-time option. If you link in more than one load balancer, you can select from the available load balancers at runtime with the *+balancer* option. In addition, you can use Metabalancer with the *+MetaLB* option to automatically decide when to invoke the load balancer, as described in :ref:`lbStrategy`. What is the migration constructor and why do I need it? ------------------------------------------------------- The migration constructor (a constructor that takes ``CkMigrateMessage *`` as parameter) is invoked when an array element migrates to a new processor, or when chares or group instances are restored from a checkpoint. If there is anything you want to do when you migrate, you could put it here. A migration constructor need not be defined for any given chare type. If you try to migrate instances of a chare type that lacks a migration constructor, the runtime system will abort the program with an error message. The migration constructor should not be declared in the *.ci* file. Of course the array element will require also at least one regular constructor so that it can be created, and these must be declared in the *.ci* file. What happens to the old copy of an array element after it migrates? ------------------------------------------------------------------- After sizing and packing a migrating array element, the array manager ``delete``\ s the old copy. As long as all the array element destructors in the non-leaf nodes of your inheritance hierarchy are *virtual destructors*, with declaration syntax: .. code-block:: c++ class foo : ... { ... virtual ~foo(); // <- virtual destructor }; then everything will get deleted properly. Note that deleting things in a packing pup happens to work for the current array manager, but *WILL NOT* work for checkpointing, debugging, or any of the (many) other uses for packing puppers we might dream up - so DON’T DO IT! Is it possible to turn migratability on and off for an individual array element? -------------------------------------------------------------------------------- Yes, call *setMigratable(false);* in the constructor. Is it possible to insist that a particular array element gets migrated at the next *AtSync()*? ---------------------------------------------------------------------------------------------- No, but a manual migration can be triggered using *migrateMe*. When not using ``AtSync`` for LB, when does the LB start up? Where is the code that periodically checks if load balancing can be done? -------------------------------------------------------------------------------------------------------------------------------------- If not using ``usesAtSync``, load balancing will not run by default. If one does not want to use ``AtSync``, but instead run in a mode where load balancing is automatically run periodically, the user must run with the *+LBPeriod