/* Define NULL pointer value */
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *)0)
#endif
#endif
program main
implicit none
integer,parameter :: nvtxs=15,Edges=22
integer :: xadj(nvtxs+1),adjncy(2*Edges)
integer :: part(nvtxs)
integer :: npart = 2
!***********metis 4.0.1***********
integer :: option(5) = [ 0, 0, 0, 0, 0 ]
integer :: edgecut
integer :: wgtflag = 0
integer :: numflag = 1
integer :: vwgt, adjwgt
!***********metis 5.1.0************
integer :: ncon =1
integer :: options(40)
integer :: objval
!**********Graph Data**************
xadj=[0, 2, 5, 8, 11, 13, 16, 20, 24, 28, 31, 33, 36, 39, 42, 44]
adjncy=[1, 5, 0, 2, 6, 1, 3, 7, 2, 4, 8, 3, 9, 0, 6, 10, 1, 5, 7, 11, 2, 6, 8, 12, 3, 7, 9, 13, 4, 8, 14, 5, 11, 6, 10, 12, 7, 11, 13, 8, 12, 14, 9, 13]
!***********metis 4.0.1***********
!参数vwgt,adjwgt等传0值进去就行了。
! call METIS_PartGraphRecursive(nvtxs,xadj,adjncy,vwgt,adjwgt,wgtflag,numflag,npart,option, edgecut, part)
!***********metis 5.1.0************
!会提示错误。原因是参数NULL()在c中(NULL()==NULL)不成立
call METIS_SetDefaultOptions(options)
options(18) =1
call METIS_PartGraphRecursive(nvtxs,ncon,xadj,adjncy,NULL(), NULL(), NULL(), npart, &
& NULL(), NULL(), options,objval,part)
write(*,*) '**********************'
write(*,*) part
write(*,*) '**********************'
end program main
TARGET = test.out
GC = ifort
CFLAGS = -fpp -g
SOR = metis_test.f90
OBJS = metis_test.o
LIBS = ~/lib/libmetis.a
$(OBJS):
@echo "-----------------------------------"
@echo "Compiling..."
@echo "-----------------------------------"
@$(GC) $(CFLAGS) -c $(SOR) $(INCLUDE)
@echo "-----------------------------------"
@echo "Linking..."
@echo "-----------------------------------"
@$(GC) $(CFLAGS) -o $(TARGET) $(OBJS) $(LIBS)
@echo "-----------------------------------"
@echo "Deleting OBJ files..."
@echo "-----------------------------------"
@rm -fr *.o
@echo "-----------------------------------"
clean:
@rm -fr *.o
@rm -fr $(TARGET)
1.07 KB, 下载次数: 0
测试代码
650 KB, 下载次数: 0
metis5.1.0库
type ST
real :: a(4)
end type ST
struct ST {
float a , b , c , d;
}
fcode 发表于 2015-8-29 08:49
在我的编译器上。这俩是一样的。NULL() 与空指针。
实际上呢,一块内存,或一个地址,只有 2**N 种可能(N ...
#include "stdio.h"
int test(int *a, int num)
{
if(!a){
printf("This is null pointer\n");
}
else{
for(int i=0; i<num; i++){
printf("Array[%d]=%d\n", i+1, a);
}
}
return 0;
}
program main
use, intrinsic:: iso_c_binding
implicit none
interface
integer(c_int) function func(array, n) bind(c, name="test")
import
implicit none
integer(c_int), intent(in), value:: n
integer(c_int), intent(in):: array(n)
end function
integer(c_int) function func2(pt, n) bind(c, name="test")
import
implicit none
integer(c_int), intent(in), value:: n
type(c_ptr), value:: pt
end function
end interface
type(c_ptr) :: a1
integer(c_int), target:: abc(5)
integer:: i
abc = [12, 12, 35, 67, 11]
a1 = c_loc(abc(1))
! Pass array directly
i = func(abc, size(abc))
! Pass address
i = func2(c_loc(abc(1)), 5)
! Pass null pointer
i = func2(c_null_ptr, 5)
! Pass null function pointer
i = func2(c_null_funptr, 5)
end program
jason388 发表于 2015-9-2 13:11
Fortran与C混合编程应该采用5楼pasuka这种方式。Fortran的c_null_ptr对应C的null指针,因此在C函数中使用nu ...
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |