jasonlarkin / p3dfft

Automatically exported from code.google.com/p/p3dfft
GNU General Public License v3.0
0 stars 0 forks source link

C++ support #47

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
See user's comment below. Please implement and test with C and C++ compilers. 

--- 

Just one more comment i forgot to mention: I'm recently using p3dfft
with C++. Therefor the original headerfile doesn't work, because the '
extern "C" ' enviroment is missing. I attached the working headerfile I
use for this reason.

#define FORT_MOD_NAME(NAME) p3dfft_mp_##NAME##_
#define FORTNAME(NAME) NAME##_

extern "C"
{
    void FORT_MOD_NAME(p3dfft_setup)(int *dims,int *nx,int *ny,int *nz, int *ow);
    void FORT_MOD_NAME(get_dims)(int *,int *,int *,int *);
    void FORT_MOD_NAME(p3dfft_ftran_r2c)(double *A,double *B);
    void FORT_MOD_NAME(p3dfft_btran_c2r)(double *A,double *B);
    void FORT_MOD_NAME(p3dfft_clean)();
    void FORTNAME(abort)();

}

void p3dfft_setup(int *dims,int nx,int ny,int nz, int overwrite)
{
    FORT_MOD_NAME(p3dfft_setup)(dims,&nx,&ny,&nz,&overwrite);
}
void get_dims(int *start,int *end,int *size,int conf)
{
    FORT_MOD_NAME(get_dims)(start,end,size,&conf);
}
void p3dfft_ftran_r2c(double *A,double *B)
{
    FORT_MOD_NAME(p3dfft_ftran_r2c)(A,B);
}

void p3dfft_btran_c2r(double *A,double *B)
{
    FORT_MOD_NAME(p3dfft_btran_c2r)(A,B);
}

void p3dfft_clean()
{
    FORT_MOD_NAME(p3dfft_clean)();
}

void FORTNAME(abort)() 
{
    abort();
}

Original issue reported on code.google.com by dmitry...@gmail.com on 15 Jun 2010 at 6:32

GoogleCodeExporter commented 9 years ago

Original comment by dmitry...@gmail.com on 21 Jun 2010 at 9:51

GoogleCodeExporter commented 9 years ago
Since the header-file in general contains function-bodies, which is not valid 
if multiple C++ files using the same header, because of multiple definition 
errors, I would suggest two solutions:
Either one has to use an #ifdef preprocessor-directive
Or make it in a formal correct way and separate function-bodies from the 
headerfile (see attached files). In the latter case one has to compile the 
p3dfft_cpp.cpp file and link its object to your main program.
In the attached files I commented out the abort() function because I'm not sure 
about its function, since it is already standard-contained in Fortran and C/C++ 
(See also Issue 34 http://code.google.com/p/p3dfft/issues/detail?id=34).

Original comment by sla...@astro.uni-wuerzburg.de on 2 Jul 2010 at 12:15

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by dan.djc...@gmail.com on 28 Jul 2010 at 12:48

GoogleCodeExporter commented 9 years ago

Original comment by dmitry...@gmail.com on 9 Aug 2010 at 7:13