i knew that mpi is used for distribued programming . my question is can i use mpi to create a communication between thread in cluster of multiprocessor and multicore machine and if this possible can i use mpi in multicore machine only to create a communication between threads
Threads inside process in MPI-2 conforming implementation are not addressable. But AFAIK there are MPI implementations which expose every thread as a distinct process (i.e. threads are addressable).
And you can always create several MPI processes on multi-core machine. If you are going to use MPI for communication between threads anyway, then this must work just fine.
But for SMP/multicore system you better use specialized tools for SMP/multicore like OpenMP/Cilk/Cilk++/TPL/PPL/Fork Join/TBB.
Or if you want to use exactly message-passing, you can employ specialized message-passing for SMP/multicore, which will have extrememly low-overhead message-passing, possibility of passing "by pointer", possibility of sharing constant data and so on.